Reputation: 21434
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
Reputation: 5462
this is purely stylistic and if you want to know more about access modifiers you can get it here
Upvotes: 0
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
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