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


C# Car.SetMiles方法代码示例

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


在下文中一共展示了Car.SetMiles方法的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);


  }
开发者ID:cbkinor,项目名称:cars,代码行数:32,代码来源:Car.cs

示例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");
    }
  }
开发者ID:Taylorgrohs,项目名称:cars,代码行数:58,代码来源:Car.cs


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