전체 글256 [C#][Study][기초다지기] 캡슐화와 추상화 캡슐화와 추상화 - 클래스나 인터페이스 외부에서 멤버를 숨기는 목적 - 사용자에게 관련 없는 데이터를 숨기는 프로세스 - 필수 기능만 표시하는 목적 - 사용자에게 관련 데이터만 표시하는 메커니즘 ex) 휴대폰 - 캡슐화 : 휴대폰 내부의 동작이 어떻게 진행되는지 사용자는 모름 - 추상화 : 사용자는 휴대폰 외부에서 다양한 유형들의 필수 기능을 사용 가능 2023. 9. 23. [C#][Study][기초다지기] foreach 문 foreach 문 - 배열과 같은 컬렉션의 내부에 값들을 하나씩 가져오면서 반복을 진행 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace foreach_loop { class Program { static void Main(string[] args) { string[] arr = new string[5]; // 배열 선언 // 배열의 값들을 저장 arr[0] = "Steven"; arr[1] = "Clark"; arr[2] = "Mark"; arr[3] = "Thompson"; arr[4] = "John"; // foreach문을 이용해 값을 검색 foreach (string name.. 2023. 9. 23. [C#][Study][기초다지기] do-while 문 do-while 문 - while문이 적어도 한 번은 실행되는 것이 보장됨 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace do_while { class Program { static void Main(string[] args) { int table, i, res; table = 12; i = 1; do { res = table * i; Console.WriteLine("{0} x {1} = {2}", table, i, res); i++; } while (i == 10); // 세미콜론 써야함에 유의! // i는 10이 아니지만 문장을 먼저 실행하고 조건을 체크하기 때문에 한번은 출.. 2023. 9. 23. [C#][Study][기초다지기] using 문 using 문 - File이나 Font와 같이 관리되지 않는 클래스, 즉 사용 후 알아서 해제가 되지 않는 자원(리소스)들은 사용자가 직접 해제(Dispose)해 주어야 한다. - 매번 해제해주는 것은 실수가 잦고, 힘들기 때문에 using문을 사용해 자동으로 자원이 해제(Dispose)되게 한다. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Using_Statement { class check_using : IDisposable { public void Dispose() { // 자원이 해제될 때 실행 Console.WriteLine("실행 2"); } } class Progr.. 2023. 9. 23. [C#][Study][기초다지기] lock 문 lock 문 - 현재 thread에서 프로그램을 실행하는동안 다른 thread의 개체를 잠그고, 진행되던 thread의 실행이 끝난 뒤에 개체의 잠금이 해제되어 다음 thread를 실행할 수 있게 함 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Lock_Statement { class Program { public void printname() { Console.WriteLine("My name is Steven Clark"); } static void Main(string[] args) { Program p = new Program(); lock (p) // lock 구문 생성.. 2023. 9. 23. [C#][Study][기초다지기] uncheck 문 uncheck 문 - 스택 오버플로우가 발생해도 예외를 무시하고 실행시킴 - 잘못된 출력이 발생할 가능성이 높음 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Unchecked_Statement { class Program { static void Main(string[] args) { int num = int.MaxValue; // int의 최대값 할당 try { unchecked { // 스택 오버플로우 발생 -> 예외를 처리하지 않고 잘못된 값을 출력함 num = num + 1; Console.WriteLine(num); } } catch (Exception e) { Cons.. 2023. 9. 23. [C#][Study][기초다지기] check 문 check 문 - 오버플로우나 언더플로우시 예외를 발생시킴 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Checked_Statement { class Program { static void Main(string[] args) { int num = int.MaxValue; // int의 최대값 할당 try { checked { // int의 최대값을 넘게하여 스택 오버플로우를 강제로 발생시킴 num = num + 1; Console.WriteLine(num); } } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.. 2023. 9. 23. [C#][Study][기초다지기] throw 문 throw 문 - 예외를 처리할 때 사용 - 예외는 catch 블록에서 처리됨 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace throw_statement { class Program { static void Main(string[] args) { int num1, num2, result; Console.WriteLine("Enter First Number"); num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Second Number"); num2 = Convert.ToInt32(Console.ReadLine.. 2023. 9. 23. [C#][Study][기초다지기] goto 문 goto 문 - label을 선언한 곳으로 돌아감 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace goto_statements { class Program { static void Main(string[] args) { string name; label: // 레이블 생성 -> 콜론 주의! Console.WriteLine("Enter your name: "); name = Console.ReadLine(); Console.WriteLine("Welcome {0}", name); Console.WriteLine("Press Ctrl + C for Exit\n"); goto label;.. 2023. 9. 23. [C#][Study][기초다지기] XOR XOR(^) - 조건이 모두 참 or 모두 거짓 인 경우에만 true 반환 ex) (1 == 0) ^ (1 == 2) => true ex) (1 == 1) ^ (1 == 1) => true ex) (1 == 0) ^ (1 == 1) => false 2023. 9. 23. [C#][Study][기초다지기] C# 사용자 입력 - ReadLine(), Read() Console.ReadLine(), Console.Read() - 사용자 입력을 읽어오는 함수 - 기본 반환형이 string이므로 int형을 반환하려면 형 변환을 해주어야 한다. // 사용자에게 받아온 문자열 입력을 Int형으로 바꾸는 방법 age = Int32.Parse(Console.ReadLine()); // Parse 사용 age = Convert.ToInt32(Console.ReadLine()); // Convert 사용 cf) 출력 함수 = Console.WriteLine("출력 값") 2023. 9. 23. [자기계발][글쓰기][책] 자청의 역행자를 읽고... 베스트셀러인 자청의 역행자 확장판을 읽었다. 그리고 내용을 까먹지 않고 상기하려고 다시 한 번 읽고 있는 중이다. 책의 내용 중에서 "경제적 자유를 위한 5가지"이라는 주제로 지금 당장 글을 써보라는 내용이 있었다. 사실 첫번째 읽을 때도 보았지만 실행력의 부족으로 생각만 하고 실행에 옮기지 못했던 것 같다. 그래서 마침 지금 책도 읽고 공부하러 나와서 노트북도 있고 책도 있겠다. 바로 실천으로 옮기는 중이다. 앞서 말한 "경제적 자유를 위한 5가지"라는 주제에 앞서 자청님의 책 '역행자'에 대한 후기?를 적어보는 게 좋을 것 같아서 이렇게 글을 시작한다. 사실 나는 그동안 책을 거의 읽지 않았다. 그리고 2주전 나는 첫 회사에 취업을 하게되었다. 그래서 회사를 다니면서 열심히 살아보자는 마음으로 입사 .. 2023. 9. 23. 이전 1 ··· 10 11 12 13 14 15 16 ··· 22 다음