Код: Выделить всё
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;
}
}
Код: Выделить всё
//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);
Подробнее здесь: https://stackoverflow.com/questions/797 ... ble-to-get
Мобильная версия