1-misol
Butun turdagi a massiv berilgan. Massivning toq elementlarini o'sish tartibida chop qiling.
using System;
using System.Linq;
class Program {
static void Main() {
int[] a = { 1, 8, 12, 3, 7, 9, 2, 4, 5 };
var oddElements = a.Where(x => x % 2 != 0).OrderBy(x => x).Select(x=>x);
foreach (var element in oddElements)
{
Console.WriteLine(element);
}
}
}
Javobi: 1
3
5
7
9
9-misol:
Satr turdagi massiv berilgan.Massivning elementlari "A" harfidan boshlangan elementlarini toping.
using System;
using System.Linq;
class Program {
static void Main() {
string[] array = { "Apple", "Ball", "Air", "Cat", "Ant", "Eat", "Fan", "Atom" };
var startsWithA = array.Where(str => str.StartsWith("A")).Select(str => str);
foreach (var word in startsWithA)
{
Console.WriteLine(word);
}
}
}Javobi:
Apple
Air
Ant
Atom
Do'stlaringiz bilan baham: |