C# 모듈
1250 단어 csharp
(double, int) t1 = (4.5, 3);
Console.WriteLine($"Tuple with elements {t1.Item1} and {t1.Item2}.");
// Output:
// Tuple with elements 4.5 and 3.
(double Sum, int Count) t2 = (4.5, 3);
Console.WriteLine($"Sum of {t2.Count} elements is {t2.Sum}.");
// Output:
// Sum of 3 elements is 4.5.
이렇게 하면 너는 쓸 필요가 없다new Tuple(item1, item2)
.원조는 방법 서명에서 간결하게 표시할 수 있다.예를 들어 이 방법은 일반 유형
IEnumerable
의 원조T
를 되돌려줍니다.public static IEnumerable<(T,T)> Pairs<T>(IEnumerable<T> ts)
{
var skip = 1;
T previous = default;
foreach (var current in ts)
{
if (skip == 0)
{
yield return (previous, current);
}
else
{
skip--;
}
previous = current;
}
}
이 방법은 쌍을 이루는 anIEnumerable
을 통해 매거한다.예를 들어
new [] { 1,2,3 }
가 있으면 다음과 같은 원조(신문법 사용)를 열거한다. (1,2)
,(2,3)
.
Reference
이 문제에 관하여(C# 모듈), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/jaredmathis/c-tuples-438n텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)