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

    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容