电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

c#程序设计教程第二版李春葆课后编程题答案VIP免费

c#程序设计教程第二版李春葆课后编程题答案_第1页
1/39
c#程序设计教程第二版李春葆课后编程题答案_第2页
2/39
c#程序设计教程第二版李春葆课后编程题答案_第3页
3/39
输入a,b求c=a+busingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceProj2_1{classProgram{staticvoidMain(string[]args){inta,b,c;Console.Write("a:");a=int.Parse(Console.ReadLine());Console.Write("b:");b=int.Parse(Console.ReadLine());c=a+b;Console.WriteLine("a+b={0}",c);}}}usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceProj2_2{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){inta,b,c;a=Convert.ToInt16(textBox1.Text);b=Convert.ToInt16(textBox2.Text);c=a+b;textBox3.Text=Convert.ToString(c);1}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidtextBox2_TextChanged(objectsender,EventArgse){}}}强制转换P38usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceProj3_1{classProgram{staticvoidMain(string[]args){inti=65,i1,i2;doubled=66.3456,d1,d2;charc='A',c1,c2;Console.WriteLine("i={0:d5},d={1:f},c={2}",i,d,c);i1=(int)d;//强制类型转换d1=i;//隐式类型转换c1=(char)i;//强制类型转换Console.WriteLine("i1={0:d5},d1={1:f},c1={2}",i1,d1,c1);i2=c;//隐式类型转换d2=(int)d;//强制类型转换c2=(char)d;//强制类型转换Console.WriteLine("i2={0:d5},d2={1:f},c2={2}",i2,d2,c2);}}}赋值两同学信息数据,并在图中输出结果P44usingSystem;namespaceProj3_2{classProgram{structStudent//类型声明应放在Main函数的外面{publicintxh;//学号publicstringxm;//姓名2publicstringxb;//性别publicintnl;//年龄publicstringbh;//班号}staticvoidMain(string[]args){Students1,s2;//定义两个结构类型变量s1.xh=101;s1.xm="李明";s1.xb="男";s1.nl=20;s1.bh="07001";Console.WriteLine("学号:{0},姓名:{1},性别:{2},年龄:{3},班号:{4}",s1.xh,s1.xm,s1.xb,s1.nl,s1.bh);s2=s1;//将结构变量s1赋给s2s2.xh=108;s2.xm="王华";Console.WriteLine("学号:{0},姓名:{1},性别:{2},年龄:{3},班号:{4}",s2.xh,s2.xm,s2.xb,s2.nl,s2.bh);}}}声明枚举类型color,给两成员赋值,定义三个变量,赋值运算输出相应值。P47usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceProj3_3{classProgram{enumColor{Red=5,Green,Blue,White=1,Black}//类型声明应放在Main函数的外面staticvoidMain(string[]args){Colorc1,c2,c3;Console.WriteLine("Red={0},Green={1},Blue={2},White={3},Black={4}",Color.Red,Color.Green,Color.Blue,Color.White,Color.Black);Console.WriteLine("Red={0},Green={1},Blue={2},White={3},Black={4}",(int)Color.Red,(int)Color.Green,(int)Color.Blue,(int)Color.White,(int)Color.Black);c1=Color.Red;c2=c1+1;c3=c2+1;Console.WriteLine("c1={0},c2={1},c3={2}",c1,c2,c3);Console.WriteLine("c1={0},c2={1},c3={2}",(int)c1,(int)c2,(int)c3);}}}位运算符运用P50usingSystem;usingSystem.Collections.Generic;3usingSystem.Text;namespaceProj3_4{classProgram{staticvoidMain(string[]args){byteb1,b2,b3;b1=10;b2=(byte)~b1;Console.WriteLine(b2);b3=(byte)(b1<<2);Console.WriteLine(b3);b1=3;b2=6;b3=(byte)(b1&b2);Console.WriteLine(b3);b3=(byte)(b1^b2);Console.WriteLine(b3);b3=(byte)(b1|b2);Console.WriteLine(b3);}}}输出常用数据类型所用字节数P52usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceProj3_5{classProgram{staticvoidMain(string[]args){Console.WriteLine("byte类型所占字节数:{0}",sizeof(byte));Console.WriteLine("char类型所占字节数:{0}",sizeof(char));Console.WriteLine("int类型所占字节数:{0}",sizeof(int));Console.WriteLine("float类型所占字节数:{0}",sizeof(float));Console.WriteLine("doubl...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

c#程序设计教程第二版李春葆课后编程题答案

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部