본문 바로가기
728x90

C#/C# 강의 정리10

C# yield문 § Yeild 문 § ◈ 호출자에게 컬렉션 데이터를 하나씩 리턴할 때 사용한다. - Collection : ArrayList, Stack, Queue, Hashtable... (Collection 정리 참조) class MyClass { static void Main(string[] args) { //int[] scores = new int[] {1, 2, 3 }; int[] arr = GetScores(); //foreach (var item in arr) foreach ( var item in GetScores()) { Console.WriteLine(item); } } static int[] GetScores( ) { int[] scores = new int[] { 1, 2, 3 }; return .. 2020. 12. 29.
C# 열거형 (Enum) § 열거형 Enum § ◈ 사용하는 목적 1. 일반적인 숫자(상수)보다 의미있는 단어로 표현하기 위하여 사용. 2. 타인을 배려할 수 있는 프로그래밍. 3. 가독성 상승 - Enum을 사용하지 않고, switch case 사용할 때의 형태 : class MyClass { static void Main(string[] args) { Order(2, 3); } static void Order(int item, int cnt) { switch (item) { case 1: Console.WriteLine("Coffee " + cnt + "잔"); break; case 2: Console.WriteLine("Green Tea " + cnt + "잔"); break; case 3: Console.WriteLine.. 2020. 12. 29.
C# 매개 변수 ref, out, method overloading ◈ parameter - 일반 변수 형식인 경우 : 변수 지정, 함수 내에서 변수에 대입될 값 지정. (원본) - 참조 + 일반 형식인 경우 : 외부 변수를 참조형식으로 가져온다. (복사의 개념, 사본) ◈ void 함수 : 특정한 리턴값이 없는 함수의 형태 class Method { public void Method_A() { } } § 출력 전용 매개 변수 ref § ◈ ref : Reference의 약어 - 참조에 의한 전달방식 조건 1. 참조가 되기 전에 변수의 초기화 필수 조건 2. 함수 내에서 값을 설정할 필요는 없다. using System; // 출력 전용 매개 변수. p198. ref, out 차이점 namespace MyNamespace { class MyClass { static vo.. 2020. 12. 27.
C# 제어문 § 제어문 § using System; // 제어문(조건문) - if class Program { static void Main(string[] args) { int score = 95; if (score >= 90) { System.Console.WriteLine("수"); } else if (score>=80) { System.Console.WriteLine("우"); } else if (score >= 70) { System.Console.WriteLine("미"); } else if (score >= 60) { System.Console.WriteLine("양"); } else { System.Console.WriteLine("가"); } } } // 제어문(조건문) - 중첩 if class Pr.. 2020. 12. 27.