3

Is there a way in C# to declare a group of variables and methods as private or public like in C++ (example below). I am just trying to avoid typing a million "public"s and "private"s.

class Foo
 {
   private:
    int Alpha;
    string Dog;

   public:
    bool Bites;
    bool Bad;
  }

I keep getting an error in C# and have exhausted my internet search abilities. Thanks

Dave S.
  • 91
  • 7
  • 1
    Some text editors allow multiline editing as a way to make this easier. In Visual Studio, hold Alt and drag to select the same column on multiple lines. I sometimes do this when I have a lot of fields and don't feel like retyping `private` for each one. – Robert Rouhani Aug 08 '13 at 02:34
  • 1
    Genius @RobertRouhani!! I just tried it. Saves a ton of typing. – Dave S. Aug 08 '13 at 02:52

1 Answers1

5

No. You need to specify visibility for each member.

private is default for members, so it is safe to omit it (unless your coding guidelines tell you must specify). More details/links - Default visibility for C# classes and members (fields, methods, etc)?

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179