Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
School/C# - Beginner (Denis)/Lesson 20/lesson_20.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
74 lines (63 sloc)
1.6 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tuple = (5, 10); | |
static void Main(string[] args) | |
{ | |
var tuple = (5, 10); | |
Console.WriteLine(tuple.Item1); // 5 | |
Console.WriteLine(tuple.Item2); // 10 | |
tuple.Item1 += 26; | |
Console.WriteLine(tuple.Item1); // 31 | |
Console.Read(); | |
} | |
(int, int) tuple = (5, 10); | |
(string, int, double) person = ("Tom", 25, 81.23); | |
var tuple = (count: 5, sum: 10); | |
Console.WriteLine(tuple.count); // 5 | |
Console.WriteLine(tuple.sum); // 10 | |
static void Main(string[] args) | |
{ | |
var (name, age) = ("Tom", 23); | |
Console.WriteLine(name); // Tom | |
Console.WriteLine(age); // 23 | |
Console.Read(); | |
} | |
static void Main(string[] args) | |
{ | |
var tuple = GetValues(); | |
Console.WriteLine(tuple.Item1); // 1 | |
Console.WriteLine(tuple.Item2); // 3 | |
Console.Read(); | |
} | |
private static (int, int) GetValues() | |
{ | |
var result = (1, 3); | |
return result; | |
} | |
static void Main(string[] args) | |
{ | |
var tuple = GetNamedValues(new int[] { 1, 2, 3, 4, 5, 6, 7 }); | |
Console.WriteLine(tuple.count); | |
Console.WriteLine(tuple.sum); | |
Console.Read(); | |
} | |
private static (int sum, int count) GetNamedValues(int[] numbers) | |
{ | |
var result = (sum: 0, count: 0); | |
for (int i = 0; i < numbers.Length; i++) | |
{ | |
result.sum += numbers[i]; | |
result.count++; | |
} | |
return result; | |
} | |
static void Main(string[] args) | |
{ | |
var (name, age) = GetTuple(("Tom", 23), 12); | |
Console.WriteLine(name); // Tom | |
Console.WriteLine(age); // 35 | |
Console.Read(); | |
} | |
private static (string name, int age) GetTuple((string n, int a) tuple, int x) | |
{ | |
var result = (name: tuple.n, age: tuple.a + x); | |
return result; | |
} |