using System; namespace Test
{
class MainClass
{
//懒人写法的单例
class Weapon
{
public static readonly Weapon Instance;
static Weapon()
{
Instance=new Weapon();
}
}
class MyWeapon
{
//static readonly和const的区别
public const int Speed=;//const必须赋值,且只能用这种方法赋值
//static readonly 可以赋值也可以不赋值,也可以在用static修饰的构造方法中赋值
public static readonly int Speed_1;
public static readonly int Speed_2=;
public static readonly int Speed_3;
static MyWeapon()
{
Speed_3=;
}
} public static void Main (string[] args)
{
//static readonly和const的联系,
//在外边只能通过类名.访问,且在外部不能赋值(二者都是只读的)
Console.WriteLine (MyWeapon.Speed_3);//
}
}
}