Class type members in C#
Forums:
class Config {
//type constant
static public readonly int maxConnections = 3;
//type fields
static public string Host;
static public int Port;
//type method
static public string GetConnection() {
return String.Format("{0}:{1}", Host, Port);
}
//type constructor
static Config() {
Host = "10.0.0.1";
}
}
Config.Port = 52;
var connection = Config.GetConnection();
//connection is "10.0.0.1:52"
Config.Host = "10.0.0.3";
connection = Config.GetConnection();
//connection is "10.0.0.3:52"
- Log in to post comments