본문 바로가기
반응형

C#41

Property(프로퍼티) namespace CSharp1 { internal class Program { //객체 지향 -> 은닉성 class Knight { protected int hp; public int HP { get { return hp; } set { hp = value; } //private set { hp = value; }막기 가능 } public int Hp//생략 가능 { get; set; } = 100;//초기값 지정 가능 /* //Getter Get함수 public int GetHp() { return hp; } //Setter Set함수 public void SetHp(int hp) { this.hp = hp; }*/ } static void Main(string[] args) { Knight knig.. 2023. 7. 10.
Interface namespace CSharp1 { internal class Program { abstract class Monster { public abstract void Shout(); } interface IFlyable { void Fly(); } interface IRunable { void Run(); } /* class SkeletonOrc : Orc, Skeleton//다중 상속 불가 { }*/ class FlyableOrc : Orc, IFlyable, IRunable//interface는 다중으로 가능 { public void Fly() { } public void Run() { } } class Orc : Monster { public override void Shout() { Console.W.. 2023. 7. 10.
Generic namespace CSharp1 { internal class Program { class MyList where T : new() { T[] arr = new T[10]; public T GetItem(int i) { return arr[i]; } } class Monster { } static void Test(T input) { } static void Main(string[] args) { /*var objV = 3; var objV2 = "Hello World"; object obj = 3;//참조 타입 object objs = "Hello World"; int num = (int)obj;//박싱 언박싱 string str = (string)objs;*/ MyList list = new MyLi.. 2023. 7. 10.
Dictionary namespace CSharp1 { internal class Program { class Monster { public int id; public Monster(int id) { this.id = id; } } static void Main(string[] args) { List list = new List(); Dictionary dic = new Dictionary(); for (int i = 0; i 2023. 7. 9.
List namespace CSharp1 { internal class Program { static void Main(string[] args) { int[] arr= new int[10]; arr[0] = 1; //List 2023. 7. 9.
다차원 배열 2차원 배열 namespace CSharp1 { internal class Program { class Map { int[,] tiles = { { 1, 1, 1, 1, 1 }, { 1, 0, 0, 0, 1 }, { 1, 0, 0, 0, 1 }, { 1, 0, 0, 0, 1 }, { 1, 1, 1, 1, 1 }, }; public void Render() { var defaultColor = Console.ForegroundColor; for (int i = 0; i 2023. 7. 9.
반응형