336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
목표 :
002의 소스코드에 메서드를 만들어 보자
소스코드:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public enum Arithmetic { plus, minus, multiple, divison } public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Clear(); } private double GetNum1() { return double.Parse(this.textNum1.Text); } private double GetNum2() { return double.Parse(this.textNum2.Text); } private void btnAdd_Click(object sender, EventArgs e) { double num1 = GetNum1(); double num2 = GetNum2(); double num = Operate(num1, num2, Arithmetic.plus); this.textResult.Text = num.ToString(); this.lbResult.Text = "+"; } private void btnClear_Click(object sender, EventArgs e) { this.Clear(); } private void Clear() { this.textNum1.Text = ""; this.textNum2.Text = ""; this.textResult.Text = ""; this.lbResult.Text = "Ready"; } private double Operate(double num1, double num2, Arithmetic ari) { double returnValue = 0.0; switch(ari) { case Arithmetic.plus: returnValue = num1 + num2; break; case Arithmetic.minus: returnValue = num1 - num2; break; case Arithmetic.multiple: returnValue = num1 * num2; break; case Arithmetic.divison: returnValue = num1 / num2; break; } return returnValue; } } } |
'Programing C# > C# 200' 카테고리의 다른 글
005 C# 윈도우 프로그래밍 발전 (0) | 2020.01.08 |
---|---|
002 C# 윈도우 프로그래밍 (0) | 2020.01.03 |
001 C# 프로그래밍 시작하기. (0) | 2019.04.19 |