Search code examples
c#fieldaccess-modifiers

Is it possible to not write `public` each time before a field in a block of public fields?


I have a class with many fields and about half of them are public. Right now it looks like this:

public int someint1, someint2, someint3;
public string str1, str2;
public bool[] boolArray;
public List<string> listOfStrings;

…and so on. And after that there are some private fields.

Is it possible to write public just once for all those public fields?


Solution

  • No, there is no way to do that in C#, you have to declare for every field its access way. In general C# tends limit access by-default, so even if do not write anything, the members will end up like private ones.