版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
相關(guān)程序設(shè)計(jì)
一、實(shí)現(xiàn)一個(gè)Window窗體應(yīng)用程序,可以實(shí)現(xiàn)畫圓、計(jì)算、畫五環(huán)
與填充顏色的功能
代碼部分
創(chuàng)建一個(gè)新類,名叫DrawPic.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
namespaceCaseOl
(
classDrawPic
(
#region屬性
//字段坐標(biāo)值
privateintx;
publicintX
(
get{returnx;}
set{
if(value<=0||value>=300)
x=150;
else
x=value;
)
)
privateinty;
publicintY
(
get{returny;}
set
(
if(value<100||value>130)
y=100;
else
y=value;
)
)
〃字段寬高
privateintp_width;
publicintP_width
get{returnp_width;}
set
if(value<=10||value>=380)
p_width=200;
else
p_width=value;
)
)
privateintp_height;
publicintP_height
(
get{returnp_height;}
set
(
if(value<=10||value>=160)
p_height=200;
else
p_height=value;
)
)
//結(jié)構(gòu)顏色
Colorc_color;
constdoublepi=3.14F;
#endregion
#region構(gòu)造函數(shù)
publicDrawPic()
(
)
III<summary>
III指定坐標(biāo)和寬高
III</summary>
III<paramname="x">x坐標(biāo)值</param>
III<paramname="y''>y坐標(biāo)值</param>
III<paramname="pwidth”>寬度</param>
III<paramname="pheight">M^</param>
publicDrawPic(stringX.stringY,stringP_width,string
P_height)
(
this.X=int.Parse(X);
this.Y=int.Parse(Y);
this.P_width=int.Parse(P_width);
this.P_height=int.Parse(P_height);
)
III<summary>
Ill指定坐標(biāo)和寬高構(gòu)造函數(shù)重載
III</summary>
III<paramname="x">x坐標(biāo)值</param>
III<paramname="y">y坐標(biāo)值</param>
III<paramname="pwidth”>寬度</param>
III<paramname="pheight">高度</param>
III<paramname="colors">Mfe</param>
publicDrawPic(stringX,stringY,stringP_width,string
P_height,Colorcolors)
(
this.X=int.Parse(X);
this.Y=int.Parse(Y);
this.P_width=int.Parse(P_width);
this.P_height=int.Parse(P_height);
this.c_color=colors;
)
#endregion
III<summary>
III實(shí)現(xiàn)畫圓
III</summary>
III<paramname="f">所需畫圓的窗體</param>
publicvoidDrawCircle(System.Windows.Forms.Formf)
//在窗體上繪制一個(gè)畫圖圖面(畫布)
Graphicsg=f.CreateGraphics();
//創(chuàng)造一個(gè)畫筆指定畫筆顏色及畫筆寬度
Penpen=newPen(Color.Black,3);
//指定畫出的圖形質(zhì)量使用消除鋸齒
g.SmoothingMode=
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
//使用畫筆畫圓
g.DrawEllipse(pen,newRectangle(x,y,p_width,p_height));
〃釋放畫布
g.Dispose();
〃釋放畫筆
pen.Dispose();
)
publicvoidFillColor(System.Windows.Forms.Formf)
(
Graphicsg=f.CreateGraphics();
Penpen=newPen(Color.Black,3);
g.SmoothingMode=
System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.lnterpolationMode
System.Drawing.Drawing2D.lnterpolationMode.High;
〃定義一個(gè)使用顏色的填充對(duì)象
Brushb=newSolidBrush(c_color);
〃填充一個(gè)形狀在固定的坐標(biāo)上
g.FillEllipse(b,x+1.5F,y+1.5F,p_height-3,
p_width-3);
g.Dispose();
pen.Dispose();
)
publicstringgetResult(intd)
(
doublec=pi*d;
doubles=pi*((d/2)*(d/2));
returnstring.Format("當(dāng)前圓的周長是{0:F2},面積是
{1:F2}!",c,s);
)
)
)
二、關(guān)于屬性的使用
創(chuàng)建一個(gè)Window窗體應(yīng)用程序
例子:學(xué)生年齡輸入合法性的判斷(成功實(shí)現(xiàn))
1、關(guān)于Form1.cs查看代碼可得:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceCase02
(
publicpartialclassForml:Form
(
publicForml()
(
lnitializeComponent();
)
privatevoidbtnMsg_Click(objectsender,EventArgse)
(
studentmyStudent=newstudent();
myStudent.Age=int.Parse(txtAge.Text.Trim());
MessageBox.Show(string.Format("年齡是:{0}",
myStudent.Age.ToStringO),"顯示年齡",MessageBoxButtons.OK,
MessageBoxIcon.Information);
//myStudent.Name="zane";
//stringgrade=myStudent.Grade;
)
privatevoidbtnNo_Click(objectsender,EventArgse)
(
MessageBox.Show("該用戶的今年\t"+txtAge.Text+
"\T歲","顯示年齡",MessageBoxButtons.OK,
MessageBoxIcon.Information);
)
)
)
2、添加類student.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceCase02
(
classstudent
privateintage;
publicintAge
get{returnage;}
set
(
if(value>0&&value<110)
(
age=value;
)
else
(
age=18;
)
)
)
privatestringname;
III<summary>
III只讀
III</summary>
publicstringName
get{returnname;}
)
privatestringgrade;
III<summary>
III只寫
III</summary>
publicstringGrade
(
set{grade=value;}
)
)
)
三、參數(shù)的值傳遞(使用ref與out進(jìn)行)
自定義計(jì)算稅后工資
事例:工資計(jì)稅的方法為:低于等于3500不計(jì)稅,超出3500的部
分按10%繳稅
查看form.cs的代碼加以編寫
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceCase03
(
publicpartialclassForml:Form
(
publicForml()
(
lnitializeComponent();
)
privatevoidbtnAccount_Click(objectsender,EventArgse)
(
intpay=int.Parse(txtPay.Text.Trim());
doubleresult=0.00F;
getResult(refpay,outresult);
MessageBox.Show(string.Format("您的工資總額是:
{0}\n超出起征點(diǎn){1:F2}元\n應(yīng)繳納{2:F2}元個(gè)人所得稅
",txtPay.Text.Trim(),pay,result),"稅率計(jì)算",
MessageBoxButtons.OK,MessageBoxIcon.Information);
)
privatevoidgetResult(refintpay,outdoubleresult)
pay-=3500;
if(pay<1500)
(
result=0.00F;
)
elseif(pay>=1500&&pay<4500)
(
result=pay*0.1F;
}
elseif(pay>=4500&&pay<9000)
(
result=pay*0.2F;
)
elseif(pay>=9000&&pay<35000)
(
result=pay*0.25F;
)
elseif(pay>=35000&&pay<55000)
result=pay*0.3F;
)
elseif(pay>=55000&&pay<80000)
(
result=pay*0.35F;
)
else
(
result=pay*0.45F;
)
)
)
)
四、構(gòu)造函數(shù)的使用
應(yīng)先添加Window窗體,代碼如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceCase04
publicpartialclassMainForm:Form
(
publicMainForm()
(
lnitializeComponent();
)
privatevoidbtnExit_Click(objectsender,EventArgse)
(
this.Close();
)
privatevoidbtnTestStudentClass_Click(objectsender,
EventArgse)
(
//Studentzhang=newStudent();
//zhang.Name="張靚靚";
//zhang.Age=20;
//zhang.Hobby="唱歌歌";
Studentscofield=newStudent("Scofield",28,"越獄
獄)
Studentzhang=newStudent("張靚靚",20,"唱歌歌");
Studentjay=newStudent("周杰杰",21,"耍雙節(jié)棍棍
");
//Studentscofield=newStudent("Scofield");
scofield.SayHi();
zhang.SayHi();
jay.SayHi();
)
)
)
事例:學(xué)生的自我介紹,代碼如下:
Student.cs代碼
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceCase04
classStudent
publicStudent(){}
publicStudent(stringname)
(
this.Name=name;
)
publicStudent(stringname,intage,stringhobby)
(
this.Name=name;
this.Age=age;
this.Hobby=hobby;
)
III<summary>
III姓名
III</summary>
privatestringname;
publicstringName
get{returnname;}
set{name=value;}
)
Ill<summary>
III年齡
III</summary>
privateintage;
publicintAge
(
get{returnage;}
set
(
〃屬性是聰明的字段
if(value>0&&value<100)
(
age=value;
)
else
(
age=18;
)
)
)
III<summary>
III愛好
Ill</summary>
privatestringhobby;
publicstringHobby
(
get{returnhobby;}
set{hobby=value;}
)
publicvoidSayHi()
(
stringmessage;
message=string.Format(
"大家好,我是{0}同學(xué),今年{1}歲了,我喜歡
{2}o",
name,this.age,this.hobby
);
MessageBox.Show(message);
)
}
)
五、應(yīng)先添加Windows窗體(MainForm.es查看代碼并進(jìn)行編
輯)
使用構(gòu)造函數(shù)實(shí)例化
1、StructStudent.cs的代碼如下
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceCaseStruct
(
publicenumGenders
(
Male,Female
)
//結(jié)構(gòu)版Student
structStructStudent
(
publicstringName;
publicGendersGender;
publicintAge;
publicstringHobby;
publicintPopularity;
publicStructStudent(stringname,Gendersgender,int
age,stringhobby):this(name,gender,age,hobby,100){}
publicStructStudent(stringname,Gendersgender,int
age,stringhobby,intpopularity)
(
this.Name=name;
this.Gender=gender;
this.Age=age;
this.Hobby=hobby;
this.Popularity=popularity;
)
publicvoidSayHi()
(
stringmessage;
message=string.Format("大家好,我是{0}同學(xué),今
年{1}歲了,我喜歡{2}。我的人氣值高達(dá){3}!",this.Name,this.Age,
this.Hobby,this.Popularity);
MessageBox.Show(message);
)
)
)
2、MainForm.es代碼如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceCaseStruct
(
publicpartialclassMainForm:Form
(
publicMainForm()
(
lnitializeComponent();
)
privatevoidbtnExit_Click(objectsender,EventArgse)
(
this.Close();
)
privatevoidbtnTest_Click(objectsender,EventArgse)
//不使用new
//TestStruct();
//使用new
TestStructNew();
)
privatevoidTestStruct()
(
StructStudentmyStu;
myStu.Age=20;
myStu.Gender=Genders.Female;
myStu.Hobby="唱歌歌";
myStu.Name="張靚靚";
myStu.Popularity=100;
myStu.SayHi();
)
privatevoidTestStructNew()
(
StructStudentmyStu=newStructStudent("張靚靚",
Genders.Female,20,"唱歌歌",100);
myStu.SayHi();
)
)
}
六、mySchool類
使用索引器知識(shí)點(diǎn)
1、MainForm.cs的代碼入下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceMySchool
(
publicpartialclassMainForm:Form
(
publicMainForm()
(
lnitializeComponent();
)
privatevoidbtnExit_Click(objectsender,EventArgse)
this.Close();
)
〃測(cè)試入口
privatevoidbtnTestStudentClass_Click(objectsender,
EventArgse)
//TestValueReference();
TestArrayParameter();
//Testlndexer();
)
〃值類型和引用類型參數(shù)演示
privatevoidTestValueReference()
//傳遞引用類型參數(shù)
Studentscofield=newStudentf'Scofield",
Genders.Male,28,"越獄獄");
scofield.SayHi();
Vote(refscofield);
scofield.SayHi();
////傳遞值類型參數(shù)
//StructStudentscofieldnew
StructStudentf'Scofield",Genders.Male,28,"越獄獄");
//scofield.SayHi();
//Vote(refscofield);
//scofield.SayHi();
)
〃數(shù)組參數(shù)演示
privatevoidTestArrayParameter()
(
int[]odd={1,3,5};
PrintArray(odd);
ChangeToEven(odd);
PrintArray(odd);
)
〃索引器演示
privatestaticvoidTestlndexer()
(
////采用數(shù)組屬性的方式
//MyClasslmyClassl=newMyClass1("T01");
//myClassl.Students[2].SayHi();
////myClassl.Students『周杰杰"].SayHi();〃編譯出
錯(cuò)
//采用索引器的方式
MyClassmyClass=newMyClass("T01");
myClass.Students[2].SayHi();
myClass.Students「周杰杰”].SayHi();
)
//投票每次投票增加人氣值1
privatevoidVote(refStudentstu)
(
stu.Popularity++;
)
〃投票每次投票增加人氣值1
privatevoidVote(refStructStudentstu)
(
stu.Popularity++;
)
privatevoidChangeToEven(int[]arr)
(
for(inti=0;i<arr.Length;i++)
(
arr[i]=i*2;
)
)
privatevoidPrintArray(int[]arr)
for(inti=0;i<arr.Length;i++)
Console.WriteLine("arr[{0}]={1i,arr[i]);
)
)
)
)
2、MyClass.es
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceMySchool
(
III<summary>
III班級(jí)類
III</summary>
classMyClass
publicMyClass(stringname)
=name;
this.students=newStudents();
)
〃班級(jí)名稱
privatestringname;
publicstringName
(
get{returnname;}
set{name=value;}
)
〃學(xué)員集合
privateStudentsstudents;
internalStudentsStudents
(
get{returnstudents;}
set{students=value;}
)
)
}
3、MyClassl.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceMySchool
(
classMyClassl
(
publicMyClassl(stringname)
(
=name;
this.students=newStudent[3];
students[O]=newStudent("Scofield",Genders.Male,
28,"越獄獄");
students[1]=newStudent("張靚靚",Genders.Female,
20,"唱歌歌");
students[2]=newStudent("周杰杰",Genders.Male,
21,"耍雙節(jié)棍棍)
)
〃班級(jí)名稱
privatestringname;
publicstringName
get{returnname;}
set{name=value;}
〃學(xué)員集合
privateStudentQstudents;
publicStudent[]Students
(
get{returnstudents;}
set{students=value;}
)
4、StructStudent.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceMySchool
〃結(jié)構(gòu)版Student
structStructStudent
publicstringName;
publicGendersGender;
publicintAge;
publicstringHobby;
publicintPopularity;
publicStructStudent(stringname,Gendersgender,int
age,stringhobby):this(name,gender,age,hobby,100){}
publicStructStudent(stringname,Gendersgender,int
age,stringhobby,intpopularity)
(
this.Name=name;
this.Gender=gender;
this.Age=age;
this.Hobby=hobby;
this.Popularity=popularity;
)
publicvoidSayHi()
stringmessage;
message=string.Format("大家好,我是{0}同學(xué),今
年{1}歲了,我喜歡{2}o我的人氣值高達(dá){3}!",this.Name,
this.Age,this.Hobby,this.Popularity);
MessageBox.Show(message);
)
}
)
5、Student.es
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceMySchool
(
publicenumGenders
(
Male,Female
)
//類版Student
classStudent
publicStudent():this("張靚靚",Genders.Female,20,“唱
歌歌",100){}
publicStudent(stringname):this(name,Genders.Male,
20,"打籃球",100){}
publicStudent(stringname,Gendersgender,intage,
stringhobby):this(name,gender,age,hobby,100){}
publicStudent(stringname,Gendersgender,intage,
stringhobby,intpopularity)
(
this.Name=name;
this.Gender=gender;
this.Age=age;
this.Hobby=hobby;
this.Popularity=popularity;
)
III<summary>
III姓名
III</summary>
privatestringname;
publicstringName
get{returnname;}
set{name=value;}
)
III<summary>
III性別
III</summary>
privateGendersgender;
publicGendersGender
(
get{returngender;}
set{gender=value;}
)
III<summary>
III年齡
III</summary>
privateintage;
publicintAge
(
get{returnage;}
set
(
〃屬性是聰明的字段
if(value>0&&value<100)
age=value;
)
else
(
age=18;
)
)
)
〃人氣指數(shù)
privateintpopularity;
publicintPopularity
(
get{returnpopularity;}
set{popularity=value;}
)
III<summary>
III愛好
III</summary>
privatestringhobby;
publicstringHobby
get{returnhobby;}
set{hobby=value;}
)
publicvoidSayHi()
(
stringmessage;
message=string.Format("大家好,我是{0}同學(xué),今
年{1}歲了,我喜歡{2}。我的人氣值高達(dá){3}!",,this.age,
this.hobby,this.popularity);
MessageBox.Show(message);
)
)
)
6、Students.es
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
namespaceMySchool
classStudents
privateStudent[]students=newStudent[3];
publicStudents()
(
students[O]=newStudent("Scofield",Genders.Male,
28,"越獄獄");
students[1]=newStudent("張靚靚",Genders.Female,
20,"唱歌歌)
students[2]=newStudent("周杰杰*Genders.Male,
21,"耍雙節(jié)棍棍)
)
〃基本索引器根據(jù)數(shù)組下標(biāo)查找學(xué)員
publicStudentthis[intindex]
(
get{returnstudents[index];}
)
〃〃與Java中的getter方法類比證明方法可以返回一個(gè)
類型
//publicStudentGetStudent(intindex)
//{
//returnstudents[index];
//)
〃重載的索引器根據(jù)姓名查找學(xué)員
publicStudentthis[stringname]
(
get
(
inti;
boolfound=false;
for(i=0;i<students.Length;i++)
(
if(students[i].Name==name)
(
found=true;
break;
)
)
if(found)
(
returnstudents[i];
)
else
returnnull;
)
)
)
)
)
七、string的相關(guān)應(yīng)用
事例:stringMethod發(fā)送電子郵件的相關(guān)代碼
1、CheckMail.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSystem.Net;
usingSystem.Net.Mail;
namespacestringMethod
(
classCheckMail
publicboolCheck(stringemail)
if(!string.lsNullOrEmpty(email))
if(email.lndexOf("@")==-1)
(
System.Windows.Forms.MessageBox.Showf7^,您輸入的電
子郵件格式不正確*"輸入提示)
returnfalse;
)
else
(
returntrue;
)
)
else
(
System.Windows.Forms.MessageBox.Show("對(duì)
不起,您必須輸入電子郵件"J輸入提示)
returnfalse;
)
)
III<summary>
Ill獲取用戶郵箱服務(wù)器地址
III</summary>
III<paramname="email"></param>
III<returns></returns>
publicstringGetMailAddress(stringemail)
(
string[]s_mail=email.Split('@');
if(string.Equals(s_mail[1],"163.com")||
string.Equals(s_mail[1],"126.com")||string.Equals(s_mail[1],
""))
(
return"";
)
elseif(string.Equals(s_mail[1],""))
(
return"";
)
elseif(string.Equals(s_mail[1],"188.com"))
(
return"";
)
elseif(string.Equals(s_mail[1],"263.net")||
string.Equals(s_mail[1],"263.")||string.Equals(s_mail[1],
""))
(
return"";
)
elseif(string.Equals(s_mail[1],"")||
string.Equals(s_mail[1],""))
(
return"/";
)
elseif(string.Equals(s_mail[1],""))
(
return"";
)
elseif(string.Equals(s_mail[1],"")||
string.Equals(s_mail[1],"")||string.Equals(s_mail[1],
""))
(
return"/cgi-bin/loginpage";
)
elseif(string.Equals(s_mail[1],"")||
string.Equals(s_mail[1],""))
return"";
)
else
(
return"http://mail."+s_mail[1].ToString();
)
)
III<summary>
III發(fā)送郵件基礎(chǔ)類
III</summary>
III<paramname="mailAdd”>郵件目標(biāo)地址</param>
III<paramname="title">郵件標(biāo)題</param>
III<paramname="bodys”>郵件主體</param>
publicvoidsetMails(stringmailAdd,stringtitle,string
bodys)
(
MailMessagemails=newMailMessage();
mails.From=newMailAddress("\"郵件發(fā)送測(cè)試
\"admin@");//郵件來源地址"\"德和木業(yè)網(wǎng)
Vmuyew@dohigh.cc"
mails.To.Add(newMailAddress(mailAdd));〃郵件目標(biāo)
地址
mails.Subject=title;〃郵件標(biāo)題
mails.Body=bodys;〃郵件主體
mails.Priority=MailPriority.High;//使用最高郵件優(yōu)先
級(jí)
mails.IsBodyHtml=true;//使用Html格式的郵件
mails.BodyEncoding=System.Text.Encoding.GetEnc
oding("GB2312");〃設(shè)置郵件主體編碼格式
SmtpCIientsc=new
SmtpClient("");//
sc.Credentials=new
NetworkCredential("admin@","mujie-hr");
//admin@mujie2009
try
(
sc.Send(mails);
)
catch(Exceptionex)
{throwex;}
)
)
}
2、Form1.cs
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespacestringMethod
(
publicpartialclassForml:Form
(
publicForml()
(
lnitializeComponent();
)
privatevoidbtnSet_Click(objectsender,EventArgse)
CheckMailcm=newCheckMail();
if(cm.Check(textBox1.Text.Trim()))
try
(
cm.setMails(textBox1.Text.Trim(),”發(fā)送郵件
測(cè)試","這是測(cè)試郵件)
System.Diagnostics.Process.Start("IExplore.exe",cm.GetMailAddr
ess(textBox1.Text.Trim()));
string[]str=textBox1.Text.Trim().Split('@');
MessageBox.Show(string.Format("郵件發(fā)送
成功!郵件用戶名是:{0},郵件地址為:
{1}”,str[0].ToString(),string.Join("@",stij),"發(fā)送郵件",
MessageBoxButtons.OK,MessageBoxIcon.Information);
)
catch(Exceptionex)
(
MessageBox.Show。對(duì)不起,消息發(fā)送失敗,
可能的失敗原因是:"+ex.Message,"發(fā)送失敗",
MessageBoxButtons.OK,MessageBoxIcon.Error);
)
)
)
)
)
八、簡易計(jì)算器
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespace簡易計(jì)算器1
(
classProgram
(
staticvoidMain(string[]args)
(
inti,j;
stringoper=
Console.WriteLine("簡易計(jì)算器V1.0");
Console.WriteLine();
Console.WriteLine("請(qǐng)輸入第一個(gè)數(shù):");
Console.Write("?");
i=newProgram().vallnput();
Console.WriteLine("請(qǐng)輸入第二個(gè)數(shù):");
Console.Write("?");
j=newProgram().vallnput();
Console.WriteLine("計(jì)算結(jié)果是:");
Console.WriteLine(newProgram().(oper,i,j));
)
privateintvallnput()
(
try
(
returnintParse(Console.ReadLine());
)
catch
(
Console.WriteLine("對(duì)不起,您輸入的數(shù)字格式不
正確,請(qǐng)重新輸入!");
Console.Write("?");
returnvallnput();
)
)
privatestringfghf(stringoper,inti,intj)
stringstr;
switch(str)
case
str=Convert.ToString(i+j);break;
case
str=Convert.ToString(i-j);break;
case
str=Convert.ToString(i*j);break;
case
str=Convert.ToString(i/j);break;
default:
Console.WhteLine("對(duì)不起,您輸入的數(shù)字格
式不正確!");break;
)
)
}
}
九、網(wǎng)開始的程序練習(xí)
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplicationl
classProgram
staticvoidMain(string[]args)
(
Console.WriteLine("HelloWorld");
)
)
)
十、打開程序后出現(xiàn)的代碼
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplicationl
(
classProgram
(
staticvoidMain(string[]args)
)
)
}
十一、變■相關(guān)(兩個(gè)變量賦值后輸出)
(—)usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceConsoleApplicationl
(
classProgram
(
staticvoidMain(string[]args)
(
Console.WriteLine("HelloWorld");
intmyAge,yourAge;
myAge=31;yourAge=21;
Console.WriteLine("我今年{0}歲,你們今年⑴歲。
",myAge,yourAge);〃占位符
)
)
)
(—)usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 預(yù)制構(gòu)件供應(yīng)購銷協(xié)議
- 家長對(duì)孩子進(jìn)行生命教育的保證書
- 大樓租賃合同范本
- 自覺維護(hù)公共秩序
- 防水工程保證書范文編寫規(guī)范
- 土方建設(shè)勞務(wù)分包合同
- 信息化顧問服務(wù)合同
- 圍墻建設(shè)合同模板范本
- 木結(jié)構(gòu)勞務(wù)分包協(xié)議
- 酒店家紡采購合同
- 幼兒園班級(jí)幼兒圖書目錄清單(大中小班)
- 烈士陵園的數(shù)字化轉(zhuǎn)型與智能服務(wù)
- 醫(yī)院與陪護(hù)公司的協(xié)議范文
- 古琴介紹(英文)(部編)課件
- DL-T5704-2014火力發(fā)電廠熱力設(shè)備及管道保溫防腐施工質(zhì)量驗(yàn)收規(guī)程
- 2024年山東省煙臺(tái)市中考道德與法治試題卷
- 女性生殖健康與疾病智慧樹知到期末考試答案章節(jié)答案2024年山東中醫(yī)藥大學(xué)
- (高清版)JGT 225-2020 預(yù)應(yīng)力混凝土用金屬波紋管
- 2023-2024學(xué)年四川省綿陽市九年級(jí)上冊(cè)期末化學(xué)試題(附答案)
- 心電圖進(jìn)修匯報(bào)
- 中醫(yī)科進(jìn)修總結(jié)匯報(bào)
評(píng)論
0/150
提交評(píng)論