■ 튜플 리터럴(Tuple Literal)을 사용하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
using System; using System.Collections.Generic; List<int> sourceList = new List<int> { 1, 2, 3, 4, 5 }; var result = Calculate(sourceList); Console.WriteLine($"{result.Count}, {result.Summary}, {result.Average}"); Console.WriteLine($"{result.Item1}, {result.Item2}, {result.Item3}"); #region 계산하기 - Calculate(sourceList) /// <summary> /// 계산하기 /// </summary> /// <param name="sourceList">소스 리스트</param> /// <returns>카운트, 합계, 평균</returns> private (int Count, int Summary, double Average) Calculate(List<int> sourceList) { int count = 0; int summary = 0; double average = 0d; foreach(int source in sourceList) { count++; summary += source; } average = summary / count; return (count, summary, average); } #endregion |