C# 16

[C# 기초공부] 파일입출력(1): 파일스트림FileStream/using/ StreamWriter, StreamReader

🐣 목차 스트림(Stream) 직렬화(Serialize) 정리 01. 파일스트림(file stream) 🟦 스트림 개요 ■ 스트림(stream)이란? 파일, 네트워크 등에서 데이터를 바이트 단위로 읽고 쓰는 클래스 ■ Stream class 는 상위 기본 클래스임 - 상속클래스들 FileStream, MemoryStream, NetworkStream, SqlFileStream등 ■ using System.IO 선언 🟦파일 스트림 FileStream ■ FileStream? 파일입출력을 다루는 기본 클래스 System.Object + System.MarshalByRefObject + System.IO.Stream + System.IO.FileStream ■ byte[] 배열로 데이터를 읽거나 저장함 → 형..

C# 2023.01.08

[C# 기초공부] 배열(2) 가변 배열

🟧 가변 배열 형식 데이터형[ ][ ] 배열명; int[ ][ ] array_name; 🐣 사용 예(1) int[행][열 ] array = new int[3][ ]; array[0] = new int[2]; array[1] = new int[3]; array[2] = new int[4]; 🐣사용 예(2) int[ ][ ] array = new int[3][ ]; array[0] = new int[2]{1,2}; array[1] = new int[3]{3,4,5}; array[2] = new int[4]{6,7,8,9}; 또는 int[ ][ ] array = new int[3][ ]; array[0] = new int[]{1,2}; array[1] = new int[]{3,4,5}; array[2] = n..

C# 2023.01.06

[C# 기초공부] 배열(1) 일차원배열과 다차원배열

🐥 목차 일차원 배열 이차원 및 다차원 배열 가변 배열 배열을 인수로 전달 배열을 리턴하는 메서드 배열의 메서드 🟩 배열 기본개념 :같은 데이터형 + 변수명 + 순차적인 메모리 나열 참조형 : new를 통해 생성 Array로 부터 파생된 참조형 foreach 사용 가능 ▶ 선언형식 데이터형[ ] 배열명; int[ ] array_name; ▶ 생성과 초기화 int[ ] array; array = new int[ ] {1, 2, 3}; array = new int[3] {1, 2, 3}; int[ ] array = new int[3] {1, 2, 3}; int[ ] array = new int[ ] {1, 2, 3}; int[ ] array = {1, 2, 3}; 🟥 일차원 배열 Array.Length 속성..

C# 2023.01.06

[C# 기초공부] 점프문(goto, continue, return, break)/ 예외 처리문(if~else)(try~catch)(try~finally)(throw)

🟨 예외 처리문 ★★★★★ ▶예외란? 런타임시 발생할 수 있는 오류 ▶ 예외 처리 방법 if ~ else try ~ catch문 사용 try { //예외가 발생할 수 있는 코드 } catch(예외처리객체 e) { //예외처리 } ▶ System.Exception 파생 객체만 사용 OverFlowException FormatException DivideByZeroException FileNotFoundException ▶ IndexOutOfRangeException : 배열의 인덱스 namespace ConsoleApp4 { class Myclass { static void Main(string[] args) { int[] array = {1,2,3}; try { array[3] = 10; } catch(..

C# 2023.01.06

[C# 기초공부] 선택문 (if~else)(switch, case)

🟧 if ~ else 🟧 switch, case -정수, 문자상수, 문자열 - 모든 case와 defaul에는 break가 반드시 있어야 함 namespace ConsoleApp4 { class Myclass { static void Main(string[] args) { int nNum = 1; switch(nNum) { case 1: Console.WriteLine("1 입니다."); break; case 2: Console.WriteLine("2 입니다."); break; } string str = "yes"; switch (str) { case "yes": Console.WriteLine("yes 입니다."); break; case "no": Console.WriteLine("no 입니다."); ..

C# 2023.01.04

[C# 기초공부] C# 기본 문법(연산자)

🟧 단항 연산자 ▶ +,-, !, ~, ++, -- 등 ▶!은 bool형에만 사용 🟧산술 연산자 ▶ *, /, %, -, + ▶stirng에서 +는 문자열 연결 정수/부동 + "문자열" ="문자열" 🟧 시프트(shift) 연산자와 관계 연산자 ▶ , >=,,>,==, != ▶ 관계 연산자의 결과는 true, false 🟧 is연산자 ▶형식 호환을 조사하는 연산자 ▶ 형식 '변수' is '클래스형' or '데이터형' A is B 결과는 true false ▶ 박싱/언박싱 변환, 참조 변환에서 사용 namespace ConsoleApp4 { class Program { static void Main(string[] args) { int nValue = 10; if(nValue is float) { Conso..

C# 2023.01.04

[C# 기초공부] 값 형식,참조형식

🟪 값형식 System.Object + System.ValueType에서 파생 변수가 직접 값을 저장하는 형 기본 데이터 형, 구조체, 열거형 선언 VS 생성(new) 🟪 참조형식 참조형식: 한 객체를 참조형 변수가 사용할 때 참조형에 의해 내용이 바뀌면 객체에 영향을 줌 clas, interface, delegate, 배열,string 객체와 참조형 사이의 대입은 객체의 메모리 주소가 복사됨 🎈 정리 기본 데이터형과 CTS형식을 익혀둔다. 데이터형에 관한 검증 코드를 작성해 보자. 값 형식과 참조 형식의 차이점을 이해하자 구분 설명 값 형식 기본 데이터형, struct, enum 참조 형식 class, interface, delegate, 배열, string namespace ConsoleApp4 { ..

C# 2023.01.04

[C# 기초공부] 구조체

public struct 구조체명 { //멤버, 속성, 메서드 } 제한 사항 - 구조체에 선언된 const, static 변수만 초기화 가능 - 구조체 안에 선언할 수 있는 생성자는 매개변수가 반드시 있어야 함 - 구조체를 같은 구조체에 대입하게 되면 값이 복사 - 구조체는 값 형식이고 클래스는 참조 형식임 - 구조체는 구조체 또는 클래스에 상속할 수 없음 - 구조체는 인터페이스를 상속하여 메서드를 구현할 수 있음 namespace ConsoleApp4 { public struct Mystruct { public int Age; } public class MyClass { public int Age; } class Program { static void Main(string[] args) { Mystru..

C# 2023.01.04

[C# 기초공부] 표준 입력

Console.ReadKey() : 사용자가 눌린 키 한 문자 정보를 리턴하는 메서드 🟨 함수원형 ✔ ReadKey는 오버로딩 됨! 매개변수가 없는 메소드 ▶ public static ConsoleKeyInfo ReadKey () 매개변수가 있는 메소드 ▶ public static ConsoleKeyInfo ReadKey(bool intercept) ⇒ true : 화면 출력 안함, false: 화면 출력 함 ✔ 리턴타입 ConsoleKeyInfo는 MSDN에서 찾아보면 구조체임 ✔ ReadKey는 내부적으로 false가 default값임 🟧 ConsoleKeyInfo 키의 문자와 Shift, Alt, Ctrl 보조키 상태 포함 ConsoleKeyInfo의 속성 ConsoleKeyInfo.Key Cons..

C# 2023.01.04