How can I built a group of constant variable in c#?
For example :
IconType {
public constant string folder = "FOLDER";
public constant string application = "APPLICATION";
public constant string system = "SYSTEM";
}
Then I need to use it like this ways IconType.system but I don't want to do declaration like IconType type = new IconType(), I want to direction access to its variable.
It just looks like JOptionPanel in java, when I want to display the icon I just need to call this JOptionPane.WARNING_MESSAGE
Just define them in a class, and since const
are implicitly static you can use them
class IconType
{
public const string folder = "FOLDER";
public const string application = "APPLICATION";
public const string system = "SYSTEM";
}
Later you can use them like:
Console.WriteLine(IconType.folder);
You may see: Why can't I use static and const together? By Jon Skeet
Seems like you would like to use enums?
public enum IconType {
Folder,
Application,
System
}
Wouldn't that not be enough?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With