class Program
{
static void Main(string[] args)
{
AutoClass.SetAutoData("法拉利F450", "法拉利", 38000, 280);//静态方法 直接 类名.方法
AutoClass myAuto = new AutoClass();//普通方法 实例化名.方法
int sudu;
string name = myAuto.GetAutoMsg(out sudu);
Console.WriteLine("汽车名字:{0} 速度:{1}", name, sudu);
Console.ReadKey();
}
}
class AutoClass
{
private static string _name;
private static string _pinpai;
private static int _money;
private static int _sudu;
public static string Name
{//为了在静态方法使用,类成员必须是静态的;
set { _name = value; }
get { return _name; }
}
public static void SetAutoData(string name, string pinpai, int money, int sudu)
{
AutoClass.Name = name;//静态方法里面的类成员必须是静态;
_name = name;
_pinpai = pinpai;
_money = money;
_sudu = sudu;
}
public string GetAutoMsg(out int sudu)
{
sudu = _sudu;
return _name;
}
}