Ranglar va fon


void PrintPerson((string name, int age) person)


Download 76.4 Kb.
bet2/4
Sana10.10.2023
Hajmi76.4 Kb.
#1696964
1   2   3   4
Bog'liq
13. Kortej, enum

void PrintPerson((string name, int age) person)

{

Console.WriteLine($"{person.name} - {person.age}");

}


var tuple = GetData(new int[] { 1, 2, 3, 4, 5, 6, 7 });
Console.WriteLine(tuple.count);
Console.WriteLine(tuple.sum);
(int sum, int count) GetData(int[] numbers)
{
var result = (sum: 0, count: numbers.Length);
foreach (var n in numbers)
{
result.sum += n;
}
return result;
}

Kortejlar ishlatilishi

Funksiyada kortejlar bilan ishlash.

var xs = new[] { 4, 7, 9 };

var limits = FindMinMax(xs);

Console.WriteLine($"Limits of [{string.Join(" ", xs)}] are {limits.min} and {limits.max}");

var (minimum, maximum) = FindMinMax(xs);

Console.WriteLine($"Limits of [{string.Join(" ", xs)}] are {minimum} and {maximum}");

(int min, int max) FindMinMax(int[] input)

{

var min = int.MaxValue, max = int.MinValue;

foreach (var i in input) {

if (i < min)

min = i;

if (i > max)

max = i;

}

return (min, max);

}

Kortejlar qiymat sifatida

Kortejlar o'rtasida o'zaro qiymat yuklash mumkin, faqat quyidagi qoidalarga amal qilish kerak:

1. Ikkala kortej bir xil miqdordagi elementlardan tashkil topgan bo'lishi kerak;

2. Kortejning mos o'rindagi elementlari turlari bir xil bo'lishi yoki bir turga keltirila olishi kerak.

(int, double) t1 = (17, 3.14);

(double First, double Second) t2 = (0.0, 1.0);

t2 = t1;

Console.WriteLine($"t2: {t2.First} and {t2.Second}");

(double A, int B) t3 = t2; // Xato

Console.WriteLine($"t3: {t3.A} and {t3.B}");

(double A, double B, double C) t4 = t2; // Xato

Console.WriteLine($"t3: {t3.A} and {t3.B}");

Kortejlarni taqqoslash

Kortejlar uchun == va != operatorlari aniqlangan. Qoidalar:


Download 76.4 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling