本文整理汇总了C#中Car.SetMakeModel方法的典型用法代码示例。如果您正苦于以下问题:C# Car.SetMakeModel方法的具体用法?C# Car.SetMakeModel怎么用?C# Car.SetMakeModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car.SetMakeModel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
// Car porsche = new Car("2014 Porsche 911", 114991, 7864);
// Car ford = new Car("2011 Ford F450", 55995, 14241);
// Car lexus = new Car("2013 Lexus RX 350", 44700, 20000);
// Car mercedes = new Car("Mercedes Benz CLS550", 39900, 37979);
// Car jalopy = new Car("Uncle Beater's Ride", 500, 250000, "Beater");
Car newCar = new Car();
newCar.SetMakeModel("Chevy Crossover");
newCar.SetMiles(83000);
newCar.SetPrice(15000);
newCar.SetCondition("Good");
Console.WriteLine(newCar.GetMakeModel());
Console.WriteLine("Miles: " + newCar.GetMiles());
Console.WriteLine("Price: $" + newCar.GetPrice());
Console.WriteLine("Condition: " + newCar.GetCondition());
Console.WriteLine(newCar.GetMakeModel() + " is in " + newCar.GetCondition() + " condition.");
// Console.WriteLine("Enter maximum price: ");
// string stringMaxPrice = Console.ReadLine();
// int maxPrice = int.Parse(stringMaxPrice);
//
// Console.WriteLine("Enter maximum miles: ");
// string stringMaxMiles = Console.ReadLine();
// int maxMiles = int.Parse(stringMaxMiles);
}
示例2: Main
public static void Main()
{
Car firstCar = new Car();
firstCar.SetMakeModel("2014 Porsche 911");
firstCar.SetPrice(114991);
firstCar.SetMiles(7864);
Car secondCar = new Car();
secondCar.SetMakeModel("2011 Ford F450");
secondCar.SetPrice(55995);
secondCar.SetMiles(14241);
Car thirdCar = new Car();
thirdCar.SetMakeModel("2013 Lexus RX 350");
thirdCar.SetPrice(44700);
thirdCar.SetMiles(20000);
Car fourthCar = new Car();
fourthCar.SetMakeModel("2018 Mercedes Benz CLS550");
fourthCar.SetPrice(39900);
fourthCar.SetMiles(37979);
List<Car> Cars = new List<Car>() { firstCar, secondCar, thirdCar, fourthCar };
Console.WriteLine("Enter maximum price: ");
string stringMaxPrice = Console.ReadLine();
int maxPrice = int.Parse(stringMaxPrice);
Console.WriteLine("Enter maximum miles: ");
string stringMaxMiles = Console.ReadLine();
int maxMiles = int.Parse(stringMaxMiles);
List<Car> CarsMatchingSearch = new List<Car>(0);
foreach(Car automobile in Cars)
{
if (automobile.WorthBuying(maxPrice, maxMiles))
{
CarsMatchingSearch.Add(automobile);
}
}
if(CarsMatchingSearch.Count != 0)
{
foreach(Car automobile in CarsMatchingSearch)
{
Console.WriteLine(automobile.GetMakeModel());
Console.WriteLine("Price: $" + automobile.GetPrice());
Console.WriteLine("Miles: " + automobile.GetMiles());
}
}
else
{
Console.WriteLine("Sorry no matches found");
}
}