본문 바로가기

분류 전체보기94

[c#] c# 상속성 객체 지향 프로그래밍의 큰 특징 상속성 / 은닉성 / 다형성 1. 상속성 using System; namespace Class { class Program { //부모 클래스 class Player { public int hp; public int attack; public Player(int hp) { this.hp = hp; } } //자식 클래스 class Mage : Player { public Mage() : base(100) { attack = 20;//부모 클래스의 필드 변수에 접근 가능 } } static void Main(string[] args) { } } } 2022. 7. 9.
[c#] CSharp this 키워드, static키워드 this 키워드 : 다른 생성자 호출! using System; namespace Class { //클래스와 구조체 차이점 class Program { class Knight { //필드 static int id = 100; int hp; int attack; Knight() { hp = 100; attack = 10; } Knight(int hp):this()// 또 다른 생성자 호출 { this.hp = hp; } Knight(int hp, int attack) : this(hp)//또 다른 생성자 호출 { this.hp = hp; this.attack = attack; } } static void Main(string[] args) { } } } static 키워드 : 인스턴스가 함께 공유, 오로지.. 2022. 7. 9.
[c#] 복사(copy)타입 변수와 참조(ref)타입 변수 절차 procedual 지향 - 함수 기반 - 로직의 유지 보수가 힘들다 => 객체 지향 프로그래밍 ! 복사 타입 변수 / 참조 타입 변수 참조 타입 변수 : 클래스 , 리스트 등 복사 타입 변수 : 구조체 using System; namespace Class { //클래스와 구조체 차이점 class Program { //Knight클래스 //클래스는 참조 타입 변수 class Knight { public int hp; public int attack; } //Mage 구조체 //구조체는 복사 타입 변수 struct Mage { public int hp; public int attack; } static void Main(string[] args) { Mage mage = new Mage(); mage... 2022. 7. 9.
[c#] c# ref, out , 메서드 오버로딩(overloading) 삼항 연산자 bool isPair = ((num%2 == 0)? true :false ) //num 이 짝수이면 isPair = true //num 이 홀수이면 isPair = false 상수 //상수 선언 const int ROCK =1 ; const int PAPER=2 ; const int SCISSORS = 0 ; //열거형 상수 enum Choice { SCISSORS, ROCK , PAPER } do while 문 do{ Console.WriteLine("일단 한번은 실행"); pa--; } while (pa > 0); //일단 한번은 실행 break && continue 문 break : for 문 ,while문 빠져나가기 ( ※ if 문 아님) continue : continue 이하 코드.. 2022. 7. 8.