首页 > 学院 > 开发设计 > 正文

深入.NET 第四章上机3 模拟小汽车

2019-11-08 02:26:21
字体:
来源:转载
供稿:网友
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 模拟汽车奔跑{    class PRogram    {        static void Main(string[] args)        {            Car car = new Car();            car.name = "奔驰";            car.color = "红";            car.Address = "德国";             car.Run();            Car b = new Car("宝马","银灰","德国");            b.Run();            b.Run(200);                       Console.ReadLine();        }    }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Collections;namespace 模拟汽车奔跑{          class Car    {        public string name{get;set;}        public string color { get; set; }        public string Address { get; set; }                                                                                                                                                                                                                                                     public Car (){ }        public Car(string n,string c,string a)        {            this.name=n;            this.color = c;            this.Address = a;        }        public void Run()        {            Console.WriteLine("我是一辆{0}车,颜色是{1}色,产地在{2}!",                this.name, this.color, this.Address);        }        public void Run(int speed)        {            Console.WriteLine("我是一辆{0}车,颜色是{1}色,产地在{2},最高车速{3}!",                this.name, this.color, this.Address, speed.ToString());        }  }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表