0

it's possible to make a class in C# where all fields and properties are const by default?

  • Imaginary example *

public class foo : const /* or readonly */ { public int baa = 3; }

Jack
  • 16,276
  • 55
  • 159
  • 284

1 Answers1

0

No, it's not.

You can make a class static though which forces all members to be static.

Ex:

public static class Constants
{
    public const int SomeId = 123;
    public const string SomeName = "foo";

    public static readonly DateTime myDateTime = new DateTime();

    public string notConstant = "test"; //does not compile
}
Wesley Wiser
  • 9,491
  • 4
  • 50
  • 69