Unity3D開發(fā)-C#語言進(jìn)階篇(面向?qū)ο笾庋b應(yīng)用詳解)

class Program
    {
        static void Main(string[] args)
        {
            //定義一個(gè)汽車類,利用自身的一個(gè)靜態(tài)方法去初始化相應(yīng)的屬性,
            CarClass Car = new CarClass();
            CarClass.CarValue("威航", "布加迪", 500, "紅色", 5);

            //然后去利用一個(gè)方法返回他的速度以及名字字段屬性:

            string names;

            int speed = CarClass.Get(out names);

            Console.WriteLine("名字:{0}  速度:{1}km/h", names, speed);

        }
    }
class CarClass
    {
        private static string name;
        private static string brand;
        private static int speed;
        private static string colour;
        private static int capacity;
        public static int count;
        public string Name
        {
            set { name = value; }
            get { return name; }
        }

        public string Brand
        {
            set { brand = value; }
            get { return brand; }

        }

        public int Speed
        {
            set { speed = value; }
            get { return speed; }

        }

        public string Colour
        {
            set { colour = value; }
            get { return colour; }
        }

        public int Capacity
        {
            set { capacity = value; }
            get { return capacity; }
        }
        public CarClass()
        {
            count++;
        }
        public static void CarValue(string _name, string _brand, int _speed, string _colour, int _capacity)
        {
            //this.brand = "";
            name = _name;
            brand = _brand;
            speed = _speed;
            colour = _colour;
            capacity = _capacity;
            Console.WriteLine("名稱:{0} 品牌:{1} 速度:{2}km/h 顏色{3} 容量:{4}", name, brand, speed, colour, capacity);

        }

        public static int Get(out string name1)
        {

            name1 = name;
            return speed;

        }

        public static void GetSpeed(out int speed1)
        {
            speed1 = speed;
        }

    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容