xdevel2000
xdevel2000

Reputation: 21434

Difference to how declare instance variables

If I have this class:

class G
{
   Texture a, b, c;
}

and

class F
{
   Texture a;
   Texture b;
   Texture c;
}

is there a difference in what access modifier is assigned or both are equivalent and thus how write them is only a style-preference?

Upvotes: 2

Views: 897

Answers (5)

mattpltt
mattpltt

Reputation: 353

No differences! There is just a style choice.

Upvotes: 1

Nivid Dholakia
Nivid Dholakia

Reputation: 5462

this is purely stylistic and if you want to know more about access modifiers you can get it here

Upvotes: 0

Armen Tsirunyan
Armen Tsirunyan

Reputation: 133072

There is no difference in C# - just stylistics (I prefer the second one).

In languages such as C and C++, it would make a difference with pointers:

int* p1, p2, p3;   // p1 is a pointer to int, but p2 and p3 aren't

In C# we don't have this problem:

int* p1, p2, p3;   // Ok, all three are pointers
int *p1, *p2, *p3;   // Invalid in C#

Also, in C++ sometimes T a, b; is not equivalent to T a; T b; even when T is not a pointer - that's the case when a coincides with T;

T T, X; //T and X are of type T

T T;
T X; //error T is not a type

Sorry, I posted more about C++ than about C#, but this is to demonstrate that C# has taken care of potential differences between the two forms which C++ hasn't :)

Upvotes: 3

Łukasz Wiatrak
Łukasz Wiatrak

Reputation: 2767

The result is the same. It's equivalent.

Upvotes: 1

BoltClock
BoltClock

Reputation: 724252

There is no functional difference; a, b and c will all be declared as private Texture fields. (private is the default access modifier for members of a class.)

Whether you choose to use one access modifier and type declaration for each one, or for all three, is purely stylistic.

Upvotes: 7

Related Questions