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;
}
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 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}"); Kortejlar uchun == va != operatorlari aniqlangan. Qoidalar:
Do'stlaringiz bilan baham: |