国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

C#學習筆記01:a+b=c 控制臺程序/窗體應用程序

2023-07-20 14:48 作者:學編程的小設計  | 我要投稿

練習:連續(xù)輸入一個數(shù)值a,

? ? ? ? ? 輸入一個數(shù)值b,計算a+b的結果。

? ? ? ? ? 用C#控制臺程序和窗體應用程序分別實現(xiàn)。


1.控制臺程序,實現(xiàn)計算a+b=c

using System;


namespace add

{

? ? class Program

? ? {

? ? ? ? static void Main(string[] args)

? ? ? ? {

? ? ? ? ? ? int a;

? ? ? ? ? ? int b;

? ? ? ? ? ? int c;

? ? ? ? ? ? Console.Write("請輸入一個數(shù)據(jù)a:");//輸入一個數(shù)據(jù)a

? ? ? ? ? ? a =Convert.ToInt32( Console.ReadLine());

? ? ? ? ? ? Console.Write("請輸入一個數(shù)據(jù)b:");//輸入一個數(shù)據(jù)b

? ? ? ? ? ? b = Convert.ToInt32(Console.ReadLine());

? ? ? ? ? ? c = a + b;

? ? ? ? ? ? Console.WriteLine("a+b="+c);//計算a+b

? ? ? ? ? ? Console.ReadLine();


? ? ? ? }

? ? }

}

————————————————————————————————

2.窗體應用程序,實現(xiàn)計算a+b=c

新建窗體應用程序,放置控件。三個TextBox,一個Button按鈕。

圖1


控件放置好,修改輸入框名稱

圖2


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 ab01

{

? ? public partial class Form1 : Form

? ? {

? ? ? ? int a;

? ? ? ? int b;

? ? ? ? int c;

? ? ? ? public Form1()

? ? ? ? {

? ? ? ? ? ? InitializeComponent();

? ? ? ? }


? ? ? ? private void dataB_TextChanged(object sender, EventArgs e)

? ? ? ? {? ??

? ? ? ? }


? ? ? ? private void button1_Click(object sender, EventArgs e)

? ? ? ? {

? ? ? ? ? ? ?a = Convert.ToInt32(dataA.Text);

? ? ? ? ? ? ?b= Convert.ToInt32(dataB.Text);

? ? ? ? ? ? c = a + b;

? ? ? ? ? ? dataC.Text = Convert.ToString(c);

? ? ? ? }


? ? ? ? private void dataA_TextChanged(object sender, EventArgs e)

? ? ? ? {? ? ? ??

? ? ? ? }


? ? ? ? private void dataC_TextChanged(object sender, EventArgs e)

? ? ? ? {

? ? ? ? }

? ? }

}


C#學習筆記01:a+b=c 控制臺程序/窗體應用程序的評論 (共 條)

分享到微博請遵守國家法律
万荣县| 海南省| 贺州市| 台州市| 德昌县| 页游| 澜沧| 台安县| 普格县| 麻城市| 平乐县| 长泰县| 梨树县| 区。| 读书| 海宁市| 河间市| 盘锦市| 天长市| 黎川县| 阳信县| 宝丰县| 宜都市| 汝阳县| 厦门市| 海门市| 方正县| 阿拉善右旗| 惠州市| 公安县| 仙桃市| 广东省| 邹城市| 莆田市| 嘉祥县| 民县| 辉县市| 大悟县| 齐河县| 宜丰县| 东丽区|