решил сдать тест в C#, у меня есть класс, который называется «Покупка» с тремя строковыми свойствами, а именно Customername, Item и Summ. Я создал свою собственную реализацию класса покупки, чьи детали показаны ниже. < /P>
public class Purchase
{
public string? CustomerName { get; set; }
public string? Item { get; set; }
public string? Amount { get; set; }
//define the constructor
public Purchase(string customerName, string item, string amount)
{
CustomerName = customerName;
Item = item;
Amount = amount;
}
}
< /code>
Я затем создал диапазон элементов покупки и добавил их в список (); В моем основном методе < /p>
//create a new list of purchases
var list = new List
();
var purchases = new Purchase[]
{
new Purchase("Timothy", "PC", "20000"),
new Purchase("David", "GF", "30000"),
new Purchase("Paloma", "PP", "40000")
};
//add the range to our list
list.AddRange(purchases);
< /code>
//sorting like this does not work
list.OrderBy(p => p.CustomerName);
//assigning to a variable results in a sorted variable like this
var sorted = list.OrderBy(p => p.CustomerName);
< /code>
So is it mandatory to assign the result of a order by LINQ query to a variable?
Подробнее здесь: https://stackoverflow.com/questions/797 ... -to-get-th