I was mildly surprised when the compiler complained about this:
public class UsefulClass
{
public const String RatingName = @\"Ratings\\rating\";
}
publ
A "variable" marked const
is a compile time construct, not an instance member. You can access it like you would a static variable:
public void SomeFunc()
{
UsefulClass useful = new UsefulClass();
String rating = UsefulClass.RatingName; // Access as if static
}
That being said, I would personally wrap this into a property if it's meant to be used as you described, like so:
public class UsefulClass
{
private const string ratingName = @"Ratings\rating";
public string RatingName { get { return ratingName; } }
}
This would make your syntax work, but also be a better design, IMO, since it doesn't expose your constants publically.