Machineboy空
C# Tuple, IEnumerable 본문
Tuple이란?
- The tuples feature provides concise syntax to group multiple data elements in a lightweight data structures.
- 여러 값을 변수 하나에 저장할 수 있는 자료형
- 값 형식
// 1. 튜플 선언(필드 이름 X) 및 값 접근
(double, int) t1 = (4.5, 3);
Console.WriteLine(t1.Item1);
Console.WriteLine(t1.Item2);
// 2. 튜플 선언(필드 이름 O) 및 값 접근
(double Sum, int Count) t2 = (4.5, 3);
Console.WriteLine(t2.Sum);
Console.WriteLine(t2.Count);
// 3. 튜플 선언 (암시적)
var t = (Sum: 4.5, Count: 3);
Console.WriteLine(t.Sum);
Console.WriteLine(t.Count);
// 1. 초기화, Initialization
(int, int, int) vertices = (90, 45, 45);
// 2. 할당, assignment
vertices = (60, 60, 60);
// 3. 반환값, return value
(bool, int) GetSameOrBigger(int num1, int num2){
return (num1 == num2, num1 > num2 ? num1 : num2);
}
// 4. 함수 인자, method argument
int Add((int, int) operands){
return operands.Item1 + operands.Item2;
}
// 5. 요소 이름, Field names
(bool success, string message) results = (true, "well done!");
bool mySuccess = result.success;
string myMessage = results.message;
var results2 = (success: true, message: "well done!");
bool mySuccess2 = results2.success;
string myMessage2 = results2.message;
IEnumerable 이란?
- Exposes an enumerator, which supports a simple iteration over a non-generic collections
- List, Stack, Queue와 같은 컬렉션에 반복이 필요한 경우 사용되는 인터페이스
IEnumerable 에 대해 간략히 설명 가능할까요? - 인프런 | 커뮤니티 질문&답변
누구나 함께하는 인프런 커뮤니티. 모르면 묻고, 해답을 찾아보세요.
www.inflearn.com
https://ansohxxn.github.io/c%20sharp/enumerate/#google_vignette
[C#] IEnumerable, IEnumerator 그리고 yield
enumerate 영어로 수를 세다. 카운팅 하다! 두 인터페이스는 열거자와 관련이 있다.(반복자와 동일한…것 같다. 아닐수도..) using System.Collections; C#의 모든 Collections 컬렉션은 IEnumerable, IEnumerator를 상
ansohxxn.github.io
추후 추가 예정
'Computer > 자료구조' 카테고리의 다른 글
Circular Buffer, Ring Buffer (0) | 2025.02.26 |
---|---|
Linked List, 연결리스트 (0) | 2025.02.04 |
Unordered Data Structure # WEEK 1 - Hashing 개념 (0) | 2024.02.22 |
Ordered Data Structures # WEEK 4 : Heaps (0) | 2024.02.20 |
Ordered Data Structures # WEEK 3 : B-Trees (0) | 2024.02.19 |