C
C# Learner
Should constant class member variables be held like this:
public class Foo
{
public const int ConstVar = 100;
}
Or like this:
public class Foo
{
public int ConstVar
{
get { return 100; }
}
}
Or even:
public class Foo
{
private const int constVar = 100;
public int ConstVar
{
get { return constVar; }
}
}
Since I've been using C# and .NET (about two weeks), I've been using
the first way, i.e. public member variables.
Which is the "correct" way to do this, according to common style?
public class Foo
{
public const int ConstVar = 100;
}
Or like this:
public class Foo
{
public int ConstVar
{
get { return 100; }
}
}
Or even:
public class Foo
{
private const int constVar = 100;
public int ConstVar
{
get { return constVar; }
}
}
Since I've been using C# and .NET (about two weeks), I've been using
the first way, i.e. public member variables.
Which is the "correct" way to do this, according to common style?