ababin 909ad8693f Добавить 'README.md' | 6 mesiacov pred | |
---|---|---|
.idea | 6 mesiacov pred | |
ConsoleApp20 | 6 mesiacov pred | |
ConsoleApp20.sln | 6 mesiacov pred | |
README.md | 6 mesiacov pred |
string[] instruments = {"Гита", "Барабаны", "Саксофон", "Фортепиано", "Труба", "Скрипка"};
var selectedInstruments = new List<string>();
foreach(string s in instruments)
{
if (s.ToUpper().StartsWith("С"))
selectedInstruments.Add(s);
}
selectedInstruments.Sort();
foreach (string s in selectedInstruments)
Console.WriteLine(s);
Вывод:
Саксофон
Скрипка
string[] instruments = {"Гитара", "Барабаны", "Саксофон", "Фортепиано", "Труба", "Скрипка"};
var selectedInstruments = from i in instruments
where i.ToUpper().StartsWith("С")
orderby i
select i;
foreach (string instrument in selectedInstruments)
Console.WriteLine(instrument);
Вывод:
Саксофон
Скрипка
string[] instruments = { "Гитара", "Барабаны", "Саксофон", "Скрипка", "Фортепиано", "Труба" };
var selectedInstruments = instruments
.Where(i => i.ToUpper().StartsWith("С"))
.OrderBy(i => i);
foreach (string s in selectedInstruments)
Console.WriteLine(s);
Вывод:
Саксофон
Скрипка
public class Instrument
{
public string Name { get; set; }
public string Type { get; set; }
public int Price { get; set; }
}
class Program
{
static void Main()
{
List<Instrument> instruments = new List<Instrument>
{
new Instrument {
Name="Гитара",
Type="Струнный",
Price=500 },
new Instrument {
Name="Скрипка",
Type="Смычковый",
Price=700 },
new Instrument {
Name="Флейта",
Type="Духовой",
Price=300 },
new Instrument {
Name="Барабаны",
Type="Ударный",
Price=1000 }
};
var expensiveInstruments = instruments.Where(i => i.Price > 600);
foreach (Instrument instrument in expensiveInstruments)
Console.WriteLine($"{instrument.Name} - {instrument.Type} - {instrument.Price}");
}
}
Вывод:
Скрипка - Смычковый - 700
Барабаны - Ударный - 1000
public class Instrument
{
public string Name { get; set; }
public string Type { get; set; }
public int Price { get; set; }
}
class Program
{
static void Main()
{
List<Instrument> instruments = new List<Instrument>()
{
new Instrument { Name = "Гитара", Type = "Струнный", Price = 500 },
new Instrument { Name = "Пианино", Type = "Клавишный", Price = 2000 },
new Instrument { Name = "Барабаны", Type = "Ударный", Price = 1000 },
new Instrument { Name = "Скрипка", Type = "Струнный", Price = 800 }
};
var result = instruments
.OrderBy(i => i.Name)
.ThenBy(i => i.Price);
foreach (Instrument i in result)
Console.WriteLine($"{i.Name} - {i.Type} - ${i.Price}");
}
};
Вывод:
Барабаны - Ударный - $1000
Гитара - Струнный - $500
Пианино - Клавишный - $2000
Скрипка - Струнный - $800