Unity3D开发-C#语言进阶篇(面向对象之封装应用详解)

class Program
    {
        static void Main(string[] args)
        {
            //定义一个汽车类,利用自身的一个静态方法去初始化相应的属性,
            CarClass Car = new CarClass();
            CarClass.CarValue("威航", "布加迪", 500, "红色", 5);

            //然后去利用一个方法返回他的速度以及名字字段属性:

            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;
        }

    }

你可能感兴趣的:(Unity3D开发-C#语言进阶篇(面向对象之封装应用详解))