목록전체 글 (240)
S_pot

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 창을 만들어준다. } }

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DialogResult Temp = MessageBox.Show("종료 전 저장할까요?","저장 여부 확인",MessageBoxButtons.YesNo); // (내용, 제목, 추가기능) if(Temp == DialogResult.Yes) { MessageBox.Show("저장되었습니다."); } else { MessageBox.Show("저장하지 않고 종료합니다..."); } } }
enum OrderState { Ordered, Paymented, Prepared, Sended}; // 상태를 숫자로 표현하지 않고, 숫자에 명칭을 붙여주는 방식 // 예를들어 결제완료, 배송준비중, 배송중, 배송완료를 표현할때 쓰인다. class Program { static OrderState OrderCheck(int orderId) { return OrderState.Ordered; } static void Main(string[] args) { if (OrderCheck(12345) == OrderState.Ordered) { Console.WriteLine("주문 완료되었습니다.") } } }

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private int iNum; private void timer1_Tick(object sender, EventArgs e) { textBox1.Text = iNum.ToString(); ++iNum; } private void button1_Click(object sender, EventArgs e) { // 타이머가 움직이고 있다면 멈추고, 움직이지 않고 있다면 움직이게 한다. if(timer1.Enabled == true) { timer1.Enabled = false; } else { timer1.Enabled = true; } } } 시:분:초 나타내기 pu..