반응형 C#41 은닉성 using static CSharp.Program; namespace CSharp { //OOP(은닉성/상속성/다형성) //자동차 //핸들 페달 차문 //전기장치 엔진 기름 외부 노출 class Car { //접근 한정자 //public protected private private int energy; public void SetEnergy(int energy) { this.energy = energy; } protected int price; } class SuperCar : Car { void Test() { price = 0;//protect는 자식 클래스에서 사용 가능 } } class Program { static void Main(string[] args) { Car car = new Car.. 2023. 7. 5. 상속 using static CSharp.Program; namespace CSharp { //OOP(은닉성/상속성/다형성) class Player//부모 클래스 혹은 기반 클래스 { static public int counter; public int id; public int hp; public int attack; public Player() { Console.WriteLine("Player 생성자 호출!"); } public Player(int hp) { this.hp = hp; Console.WriteLine("Player hp 생성자 호출"); } public void Move() { Console.WriteLine("Move"); } public void Attack() { Console.Write.. 2023. 7. 5. static 이란 using static CSharp.Program; namespace CSharp { class Knight { static public int counter;//오로지 1개만 존재! public int id; public int hp; public int attack; static public void Test() { counter++;//static 함수 내에서는 static만 값변경 가능 } static public Knight CreateKnight() { Knight knight = new Knight(); knight.hp = 100; knight.attack = 1; return knight; } public Knight() { id = counter; counter++; hp = 100; .. 2023. 7. 5. 생성자 using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Transactions; using static CSharp.Program; namespace CSharp { //객체 (OOP Object Oriented Programming) //Knight //속성 : hp , attack, pos; //기능 : Move, Attack, Die; class Knight { public int hp; public int attack; public Knight() { hp = 100; attack = 10; Console.WriteLine("생성자 호출!"); } public Knight.. 2023. 7. 5. 스택과 힙 스택(stack) 불안정하고 임시적으로 사용하는 메모리 힙(heap) 프로그램이 실행하면서 실시간으로 할당하는것 c#같은 경우는 힙메모리에서 더이상 필요 없는 부분은 걸비지 컬렉터에서 지워준다 2023. 7. 5. 복사(값)와 참조 using static CSharp.Program; namespace CSharp { //객체 (OOP Object Oriented Programming) //Knight //속성 : hp , attack, pos; //기능 : Move, Attack, Die; class Knight { public int hp; public int attack; public Knight Clone() { Knight knight = new Knight(); knight.hp = hp; knight.attack = attack; return knight; } public void Move() { Console.WriteLine("Knight Move"); } public void Attack() { Console.Wri.. 2023. 7. 4. 이전 1 2 3 4 5 6 7 다음 반응형