목록C# (132)
S_pot

class SmartInt { public int[] iNum; public SmartInt(int Len) { iNum = new int[Len]; for (int i = 0; i < iNum.Length; i++) { iNum[i] = 100 + i; } } public int this[int i] { get { return iNum[i]; } set { iNum[i] = value; } } } class Program { static void Main(string[] args) { SmartInt I = new SmartInt(5); Console.WriteLine(I.iNum[0]); // 100 Console.WriteLine(I.iNum[1]); // 101 Console.WriteLine(I..

namespace _210603_010 { abstract class Musician { public abstract void greet(); } class Singer : Musician { public override void greet() { Console.WriteLine("안녕하세요 저는 싱어입니다."); } } class Drum : Musician { public override void greet() { Console.WriteLine("안녕하세요 저는 드러머입니다."); } } class Bell : Musician { public override void greet() { Console.WriteLine("안녕하세요 저는 벨 연주자입니다."); } } class Piano : Music..

namespace _210603_009 { abstract class Human { abstract public void Talk(); } abstract class Kor : Human { public override void Talk() { Console.WriteLine("안녕하세요..."); } } abstract class Jpn : Human { public override void Talk() { Console.WriteLine("안녕하시므니까..."); } } class Hong : Kor { } class Dama : Jpn { } class Program { static void Main(string[] args) { Hong aHong = new Hong(); Dama aDama = ..
자식메서드에서 추상클래스를 반드시 구현하도록 하기 위해서 사용한다. namespace _210603_008 { abstract class Smart // 추상 메소드를 가진 클래스는 추상클래스가 됨. { abstract public void Test1(); // 추상 메서드 public abstract void Test2(); // 추상 메서드 // 1. abstract가 붙는다. // 2. 본문(Body)이 없다. // 3. private으로 선언할 수 없다. } abstract class Child1 : Smart { // 추상 메서드를 가진 클래스를 상속 받으면 추상클래스가 된다. } class Child2 : Smart { // 부모의 추상 메서드를 모두 구현하면 일반 클래스가 된다. public..

static void Main(string[] args) { List list = new List() { 52, 273, 32, 64 }; foreach (var Temp in list) { Console.WriteLine(Temp); } Console.WriteLine("--------------------------"); list[2] = 100; // 배열값을 수정해준다. foreach (var Temp in list) { Console.WriteLine(Temp); } Console.WriteLine("--------------------------"); list.Insert(1, 500); // 1번 배열자리에 500삽입 foreach (var Temp in list) { Console.Writ..
class Box { // propfull입력하고 탭키를 두번눌러 자동생성한다. private int width; public int Width { get { return width; } set { if (width > 0) { width = value; } else { width = 0; Console.WriteLine("입력값 오류로 0으로 설정되었습니다."); } } } private int height; public int Height { get { return height; } set { if (height > 0) { height = value; } else { height = 0; Console.WriteLine("입력값 오류로 0으로 설정되었습니다."); } } } }
// 겟터와 셋터: 변수를 바로 변경할 수는 없지만 변수를 변경하는 메서드를 만든다. // 변수값을 직접 입력하는 것이 아닌 메서드를 통해서 입력하게 해주는 것 public int Area() { return this.width * this.height; } // 겟터(Getter) public int GetWidth() { return width; } public int GetHeight() { return height; } // 셋터(Setter) public void SetWidth(int width) { if (width > 0) { this.width = width; } else { Console.WriteLine("높이는 자연수를 입력해주세요"); } } public void SetHeight..
// 캡슐화 class Box { private int width; private int height; public Box(int width, int height) { if (width > 0 && height > 0) { this.width = width; this.height = height; } else { this.width = 0; this.height = 0; // 음수입력을 막아줌 Console.WriteLine("입력값 오류로 변수 값이 모두 0으로 설정되었습니다."); } } public int Area() { return this.width * this.height; } }
// 제네릭은 메서드 오버라이드를 하면서 생기는 불필요한 코드의 중복을 최소화할 수 있다. // Generic 메서드 방식으로 작성 static string Smart(T Num) { return Num.ToString(); } static void Main() { string Temp1; string Temp2; string Temp3; string Temp4; Test aTest = new Test(); // Generic 메서드 호출 Temp1 = Smart(1000); // Smart(1000); Temp2 = Smart(30.14); // Smart(30.14); Temp3 = Smart(true); // Smart(true); Temp4 = Smart(aTest); // Smart(aTest)..
public partial class Form1 : Form { public Form1() { InitializeComponent(); IsMdiContainer = true; } class Smart : Form { public Smart() { Text = "스마트 클래스의 폼 창 만들기"; } } private void button1_Click(object sender, EventArgs e) { Smart aSmart = new Smart(); //aSmart.MdiParent = this; // 폼안에 창이 밖으로 나가지 않게 만들어준다. // aSmart.Show(); // Modeless 창 aSmart.ShowDialog(); // Modal 창을 만들어준다. } }