0% found this document useful (0 votes)
6 views1 page

LINQ Methods for Car Collection Management

The document contains a C# program that defines a 'Car' class with properties for Brand, Model, and Price. It creates a list of car objects and uses LINQ to group them by brand, selecting the car with the highest price for each brand. The results are then printed to the console, displaying the brand, model, and price of the highest-priced cars.

Uploaded by

shubham kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

LINQ Methods for Car Collection Management

The document contains a C# program that defines a 'Car' class with properties for Brand, Model, and Price. It creates a list of car objects and uses LINQ to group them by brand, selecting the car with the highest price for each brand. The results are then printed to the console, displaying the brand, model, and price of the highest-priced cars.

Uploaded by

shubham kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using System;

using [Link];
using [Link];
using [Link];

class Car
{
public string Brand { get; set; }
public string Model { get; set; }
public decimal Price { get; set; }
}

public class Program


{
public static void Main()
{
List<Car> cars = new List<Car>
{
new Car { Brand = "Audi", Model = "A4", Price = 35000 },
new Car { Brand = "Audi", Model = "M4", Price = 36000 },
new Car { Brand = "Audi", Model = "AM4", Price = 43000 },
new Car { Brand = "BMW", Model = "LX", Price = 50000 },
new Car { Brand = "BMW", Model = "LX4", Price = 24000 },
new Car { Brand = "BMW", Model = "LX9", Price = 59000 },
// Add more cars as needed
};

/*var highestPriceCarsByBrand = cars


.GroupBy(c => [Link])
.Select(group => [Link](c => [Link]).First());*/

var highestPriceCarsByBrand = from car in cars


group car by [Link] into brandGroup
let highestPriceCar = [Link](c
=> [Link]).First()
select highestPriceCar;

// Display the results


foreach (var car in highestPriceCarsByBrand)
{
[Link]([Link]("Brand: {0}, Model: {1}, Price:
{2}",[Link], [Link],[Link]));
}
}
}

You might also like