本文整理汇总了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();
}
示例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(_);
}
示例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(_);
}
示例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);
};
};
});
}