当前位置: 首页>>代码示例>>C#>>正文


C# Car.Drive方法代码示例

本文整理汇总了C#中Car.Drive方法的典型用法代码示例。如果您正苦于以下问题:C# Car.Drive方法的具体用法?C# Car.Drive怎么用?C# Car.Drive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Car的用法示例。


在下文中一共展示了Car.Drive方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            // Challenge Objectives
            // - Instantiate a Car object
            // - Set values for the data
            // - Call the two methods
            Car Hybrid = new Car();

            // Configure Hybrid
            Hybrid.Make = "Toyota";
            Hybrid.Model = "Prius";
            Hybrid.Color = "Black";

            // Check Hybrid Properties
            Console.WriteLine("Make: " + Hybrid.Make);
            Console.WriteLine("Model: " + Hybrid.Model);
            Console.WriteLine("Color: " + Hybrid.Color);

            // Use Hybrid
            Hybrid.Drive();
            Hybrid.Stop();

            // Instructor's Solution
            CarIS myCar = new CarIS();

            myCar.make = "Chevrolet";
            myCar.model = "Camaro";
            myCar.color = "Black";

            myCar.Drive();
            myCar.Stop();
        }
开发者ID:RickyGenz,项目名称:Learning-C-Sharp,代码行数:32,代码来源:Program.cs

示例2: the_car_encapusulates_the_incrementing_of_miles

        public void the_car_encapusulates_the_incrementing_of_miles()
        {
            Car car = new Car();

            car.Drive(1000);

            car.MilesDriven.ShouldBe(_);
        }
开发者ID:seanbiefeld,项目名称:mentoring,代码行数:8,代码来源:AboutEncapsulation.cs

示例3: the_automobile_can_be_extended

        public void the_automobile_can_be_extended()
        {
            Car car = new Car();

            car.Drive(1000);

            car.ReplaceEngine();

            car.MilesDriven.ShouldBe(_);
        }
开发者ID:seanbiefeld,项目名称:mentoring,代码行数:10,代码来源:AboutEncapsulation.cs

示例4: when_driving_car

    void when_driving_car()
    {
        it["should throw error if car isn't started"] =
            expect<InvalidOperationException>(() =>
            {
                Car car = new Car(tankSize: 10, mpg: 1);
                car.Drive(10);
            });

        new[]
        {
            new { gasInTank = 10, mpg = 1,  miles = 10.0, expectedDistance = 10.0,
                  gasLeft = 0.0, running = false, lowfuel = true, onEmpty = true },

            new { gasInTank = 10, mpg = 2,  miles = 5.0,  expectedDistance = 5.0,
                  gasLeft = 7.5, running = true, lowfuel = false, onEmpty = false },

            new { gasInTank = 10, mpg = 10, miles = 10.0, expectedDistance = 10.0,
                  gasLeft = 9.0, running = true, lowfuel = false, onEmpty = false }
        }.Do(example =>
        {
            context["with {0} gallon(s) of gas, mpg: {1}, driving: {2} miles"
                .With(example.gasInTank, example.mpg, example.miles)] = () =>
            {
                Car car = null;

                before = () =>
                {
                    car = new Car(example.gasInTank, example.mpg);
                    car.FillTank(example.gasInTank);
                };

                act = () => car.Drive(example.miles);

                it["should have made it {0} miles".With(example.expectedDistance)] = () =>
                {
                    car.Odometer.should_be(example.expectedDistance);
                };

                it["should have {0} gallons left in tank".With(example.gasLeft)] = () =>
                {
                    car.GasInTank.should_be(example.gasLeft);
                };

                it["should {0} running".With(example.running ? "be" : "not be")] = () =>
                {
                    car.IsRunning.should_be(example.running);
                };

                it["should {0} low fuel".With(example.lowfuel ? "have" : "not have")] = () =>
                {
                    car.IsLowOnFuel.should_be(example.lowfuel);
                };
            };
        });
    }
开发者ID:DevlinLiles,项目名称:NSpec,代码行数:56,代码来源:describe_car.cs


注:本文中的Car.Drive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。