upcasting이란 자식클래스의 형식에서 부모클래스의 형식으로 casting 바뀌는것을 말한다. 즉 하나의 매개변수형 (상위)로 상속 받은 자식클래스의 매개변수형을 받아 오는것이다. using System; namespace casting_1 { public class Sample { } public class Sample1 : Sample { } public class Sample2 : Sample { } public class Sample3 : Sample { } public class SamplePrint { /* 자식클래스가 추가될때마다 매서드를 오버로딩 시켜주어야함 public void Print(Sample1 sample) { Console.WriteLine("Print " + sample)..
docs.microsoft.com/ko-kr/dotnet/api/system.guid.newguid?view=net-5.0 Guid.NewGuid 메서드 (System) Guid 구조체의 새 인스턴스를 초기화합니다.Initializes a new instance of the Guid structure. docs.microsoft.com using System; namespace guid { class Program { static void Main(string[] args) { for (var i = 1; i < 15; i++) { var uid = Guid.NewGuid().ToString(); Console.WriteLine($"#{i}. {uid}"); } } } }
docs.microsoft.com/ko-kr/dotnet/csharp/programming-guide/classes-and-structs/abstract-and-sealed-classes-and-class-members 추상 및 봉인 클래스와 클래스 멤버 - C# 프로그래밍 가이드 C#의 추상 키워드를 사용하여 불완전한 클래스와 클래스 멤버를 만듭니다. Sealed 키워드는 이전 가상 클래스 또는 클래스 멤버의 상속을 방지합니다. docs.microsoft.com abstract는 추상 클래스로써 자식클래스에서 override 할 때 사용되며 다음과 같은 특징이 있다. 1. abstract 매서드 선언시에는 body ({})부분이 없다. 2. abstract 매서드 선언시에는 클래스 앞에 abstract..
docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/keywords/override override 한정자 - C# 참조 override(C# 참조)override (C# reference) 이 문서의 내용 --> override 한정자는 상속된 메서드, 속성, 인덱서 또는 이벤트의 추상 또는 가상 구현을 확장하거나 수정하는 데 필요합니다.The override modifier is re docs.microsoft.com override는 자식클래스에서 부모클래스에서 받은 메서드를 재정의해서 사용할때 사용한다. override를 해주는 부모클래스에서는 각각 virtual과 abstract 이 두가지로 나누어지는데 기본적으로 부모클래스의 역할이 있고 자식..
docs.microsoft.com/en-us/dotnet/api/system.timespan?view=net-5.0 TimeSpan Struct (System) Represents a time interval. docs.microsoft.com DateTime에 이어 TimeSpan이라는 클래스도 있다. 마찬가지로 static으로도 쓰일수 있고, 인스턴스화 이후에 사용해도 된다. using System; namespace timespan { class Program { static void Main(string[] args) { // Create var timeSpan = new TimeSpan(1, 2, 3); var timeSpan1 = new TimeSpan(1, 0, 0); var timeSpan..
docs.microsoft.com/en-us/dotnet/api/system.datetime?view=net-5.0 DateTime Struct (System) Represents an instant in time, typically expressed as a date and time of day. docs.microsoft.com C#에서도 다른언어와 마찬가지로 날짜와 시간을 다룰수있는 클래스가 있다. DateTime 자체에서 static으로 불러와서 사용해도되고 new 키워드를 통해서 인스턴스화 해도 된다. using System; namespace datetime { class Program { static void Main(string[] args) { // Static var staticNow ..
docs.microsoft.com/en-us/dotnet/api/system.io.path?view=net-5.0 Path Class (System.IO) Performs operations on String instances that contain file or directory path information. These operations are performed in a cross-platform manner. docs.microsoft.com 마지막으로 Path System.IO에 있는 내용들을 활용하면 파일관련사항들은 처리 할 수 있다. using System.IO; namespace __Path { class Program { static void Main(string[] args) { var..
docs.microsoft.com/en-us/dotnet/api/system.io.directory?view=net-5.0 Directory Class (System.IO) Exposes static methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited. docs.microsoft.com 일전의 File과 FileInfo와의 차이처럼 각각 static이냐 인스턴스화 시키냐의 차이정도 있다. 단순하게 쓸 경우는 Directory 여러가지 작업을 할 경우는 DirectoryInfo using System; using System.IO; namespace ..
docs.microsoft.com/ko-kr/dotnet/api/system.io.fileinfo?view=net-5.0 FileInfo Class (System.IO) Provides properties and instance methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects. This class cannot be inherited. docs.microsoft.com File과 FileInfo는 각각 System.IO에서 지원해준다. 두가지의 가장 큰 차이점은 File은 static 매서드 이고 FileInfo는 instance 매서드이..
Generic Type은 특정 클래스나 함수에서 여러가지 데이터타입을 인자값으로 받거나 리턴해줄때 사용한다. 기본적인 사용방법은 다음과 같다. // T는 다른 임의의 값을 넣어도 상관없다. public static class GenericSample { public static void Print(T _Value) { Console.WriteLine(_Value); } } public class GenericSample2 { } 위와 같이 선언해준다음에 위치에 원하는 데이터 타입을 넣어준다. 아래와 같은 상황에서 쓰이면 유용하다. public static class Sample { public static void Print(int _Value) { Console.WriteLine(_Value); } p..
상속 (inheritance)은 부모 클래스의 프로퍼티와 메서드를 자식 클래스에서 사용 할수 있게 해주는것이다. 여러가지 클래스에 공통적으로 들어가는 부분이 있으면 활용하기 좋다. c#에서의 상속은 : 키워드를 통해서 상속 받을 수 있다. namespace inheritance { // 부모 class public class Sample1 { public int data1 { get; set; } public string data2 { get; set; } public bool data3 { get; set; } public void Hello() { Console.WriteLine("Hello ..."); } public void Print(string _value) { Console.WriteLine..
c#의 접근 제한자 (엑세스 한정자)는 크게 4가지로 이루어져 있다. public : 어디서든 접근 가능 private : 해당 클래스 내부에서만 접근 가능 internal : 같은 어셈블리 내에서만 접근 가능 protected : 파생 클래스 상속받은 클래스에서 접근 가능 많이 사용하는건 public과 private이다. class의 접근 제한자 기본값은 internal이며 class내의 필드나 메서드의 접근 제한자 기본값은 private이다. access_modifier 네임스페이스 using access_modifier2; using System; namespace access_modifier { // 기본값은 internal 따라서 같은 어셈블리 (프로젝트)에서는 사용이 가능하다. class Sa..