2

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?

xdevel2000
  • 20,780
  • 41
  • 129
  • 196

5 Answers5

7

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.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
3

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 :)

Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
1

The result is the same. It's equivalent.

Łukasz Wiatrak
  • 2,747
  • 3
  • 22
  • 38
1

No differences! There is just a style choice.

mattpltt
  • 333
  • 1
  • 4
  • 18
0

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

Community
  • 1
  • 1
Nivid Dholakia
  • 5,272
  • 4
  • 30
  • 55