First create a POCO that represents according to your data:
public class Car
{
public string Name { get;set;}
public int Amount { get;set;}
public int Year { get;set;}
public decimal Price { get;set;}
public override String ToString()
{
return String.Format("Name:{0},Amount{1},Year:{2},Price:{3}",Name,Amount,Year,Price);
}
}
and then read the file and then create a collection and then use linq to get the car with highest price and print it out:
var lines = File.ReadAllLines("cars.text");
int totalCars = Convert.ToInt32(lines[0]);
List<Car> cars = new List<Car>();
for(int i = 1; i < totalCars; i++)
{
var line = lines[i];
var carInfo = line.Split(';');
Car car = new Car();
car.Name = carInfo[0];
car.Amount = Convert.ToInt32(carInfo[1]);
car.Year = Convert.ToInt32(carInfo[2]);
car.Price = Convert.ToDecimal(carInfo[3]);
cars.Add(car);
}
var carWithHighestPrice = cars.OrderByDescending(x=>x.Price).First();
Console.WriteLine(carWithHighestPrice);