본문 바로가기

:SERVER/C#(C Sharp)

(7)
클래스 특성 - 상속성/은닉성/다형성 1. 상속성 using System; namespace CSharp { // 객체 지향 OOP; Object Oriented Programming // [부모 클래스; 기반 클래스] class Player { // 필드. 필드는 인스턴스마다 제각각인 값을 가진다. static public int counter; // Knight 인스턴스 모두 공유. 오로지 하나만 존재. public int id; public int hp; public int attack; public Player() { System.Console.WriteLine("Player생성자 호출"); } public Player(int hp) { this.hp = hp; System.Console.WriteLine("Player-hp생성자 호..
클래스, 생성자, static using System; namespace CSharp { // 객체 지향 OOP; Object Oriented Programming class Knight { // 필드. 필드는 인스턴스마다 제각각인 값을 가진다. static public int counter; // Knight 인스턴스 모두 공유. 오로지 하나만 존재. public int id; public int hp; public int attack; public void test() { } // 인스턴스에 종속됨 static public void test2() { // 클레스에 종속됨 // 정적 속성, 정적 메소드에서는 this키워드 사용 금지 // 정적 속성에만 접근 가능. } static public Knight CreateKnight() ..
스택,힙 메모리, 클래스 using System; namespace CSharp { // 객체 지향 OOP; Object Oriented Programming // 속성, 기능 // 참조(ref)를 이용한다. class Knight { public int hp; public int attack; public Knight Clone() { Knight knight = new Knight(); knight.hp = this.hp; knight.attack = this.attack; return knight; } public void Move() { System.Console.WriteLine("Knight Move"); } public void Attack() { System.Console.WriteLine("Knight Attac..
함수, ref, out 1. 함수, ref, out using System; namespace CSharp { class Program{ // Method, Function, ..함수 // 한정자 반환형식 이름(매개변수 목록) {} static void HelloWorld() { System.Console.WriteLine("Hello World"); } // 복사값을 넘긴다 static int add(int a, int b){ return a+b; } // 참조값을 넘긴다(ref) static void addOne(ref int num){ num+=1; } // 리턴 값을 여러개 보내고 싶을 때 사용. 참조값을 리턴함(out) static void divide(int a, int b, out int result1, out i..
반복문 1. while문, do-while문 using System; namespace CSharp { class Program{ // Main function static void Main(string[] args) { // 반복문 while // 참이면 while문을 계속 반복. 거짓이면 while문을 탈출 int i = 5; while (i>0) { i--; Console.WriteLine("hello world"); //5번 출력 } // do~while문 do { // 한번은 do 안의 내용을 실행하고, while문이 참이면 반복 } while (); // 거울아 거울아 string answer; do { Console.WriteLine("강사님은 잘생기셨나요?(y/n)"); answer = Conso..
분기문(if문, switch문, 삼항연산자) 1. 분기문 - if문 - switch문 - 삼항연산자 using System; namespace CSharp { class Program{ // Main function static void Main(string[] args) { // 분기문 int hp = 100; bool isDead = (hp
C# 변수, 문자열 1. 변수 using System; namespace CSharp { class Program{ // Main function static void Main(string[] args){ int hp = 100; // byte(1 byte, 0~255), short(2 byte, -3만x~3만x), int(4 byte, -21억~21억), long(8 byte) // sbyte(1 byte, -128~127), ushort(2 byte, 0~6만x), uint(4 byte, 0~43억x), ulong // 10진수(0-9로 표기) // 00 01 02 03 04 05 06 07 08 09 > 10 11 12... // 2진수(0,1로 표기) // 0b00 0b01[1] > 0b10[2] 0b11 > 0b1..