ImageVerifierCode 换一换
格式:DOC , 页数:12 ,大小:84.01KB ,
资源ID:11314252      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-11314252.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(c#实例源代码.doc)为本站会员(HR专家)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

c#实例源代码.doc

1、【实例 1-1】using System;using System.Collections.Generic;using System.Text;namespace _class Programstatic void Main(string args)System.Console.WriteLine(“恭喜你,学会了C#编程!“);System.Console.ReadLine();【实例 1-2】private void Form1_Load(object sender, EventArgs e)this.Text=“这是一窗口!“;Label lbShow = new Label();lbS

2、how.Location = new Point(40,50);lbShow.AutoSize = true;lbShow.Text = “恭喜你学会编程了!“;this.Controls.Add(lbShow); int x, y;x = new int5 1,2,3,4,5;y = new int5;y = x;foreach (int a in y)lbShow.Text += a.ToString();this.Controls.Add(lbShow);【实例 2-1】using System;using System.Windows.Forms;namespace TestEnump

3、ublic partial class TestEnum : Form/Visual Studio .Net自动生成的构造函数,后文示例将全部省略public TestEnum() InitializeComponent();enum MyEnum a = 101, b, c, d = 201, e, f ; /声明枚举型private void TestEnum_Load(object sender, EventArgs e)MyEnum x = MyEnum.f; /使用枚举型MyEnum y = (MyEnum)202;string result =“枚举数x的值为“;result +=

4、 (int)x; /将x转换为整数result += “n枚举数y代表枚举元素“ + y;lblShow.Text = result;【实例 2-2】using System;using System.Windows.Forms;namespace TestStrupublic partial class TestStru : Formstruct Student /声明结构型/声明结构型的数据成员public int no;public string name;public char sex;public int score;/声明结构型的方法成员public string Answer()

5、string result=“该学生的信息如下:“;result += “n学号:“ + no; /“n“为换行符result += “n姓名:“+ name;result += “n性别:“+ sex;result += “n成绩:“+ score;return result; /返回结果;private void TestEnum_Load(object sender, EventArgs e)Student s; /使用结构型s.no = 101;s.name = “黄海“;s.sex = 男;s.score = 540;lblShow.Text = s.Answer(); /显示该生信

6、息lblShow.Text += “nn“+DateTime.Now; /显示当前时间【实例 2-3】using System;class TestConstantstatic void Main(string args)Console.WriteLine(0).GetType(); /有符号的32位整型常量Console.WriteLine(0U).GetType(); /无符号的32位整型常量Console.WriteLine(0L).GetType(); /64位的长整型常量Console.WriteLine(0F).GetType(); /32位的浮点型常量Console.WriteL

7、ine(0D).GetType(); /64位的双精度型常量Console.WriteLine(0M).GetType(); /128位的小数型常量Console.WriteLine(0).GetType(); /16位的字符型常量Console.WriteLine(“0“).GetType(); /字符串常量Console.WriteLine(0.0).GetType(); /64位的双精度型常量Console.WriteLine(true).GetType(); /布尔型常量Console.WriteLine(u0041).GetType(); /16位的字符型常量Console.Read

8、Line();【实例 2-4】using System;class TestVariablestatic void Main(string args)int a = 12, b = 15, c, d, e;c = a + b;d = a - b;e = a * b;Console.WriteLine(“c=0td=1te=2“, c, d, e);【实例 2-5】using System;using System.Windows.Forms;namespace TestVariablepublic partial class TestOperator : Formprivate void Te

9、stVariable_Load(object sender, EventArgs e)int i = 5, j = 5, p, q;p = (i+) + (i+) + (i+);q = (+j) + (+j) + (+j);string t = “ “;lblShow.Text = i + t + j + t + p + t + q;【实例 2-6】using System;using System.Windows.Forms;namespace TestVariablepublic partial class TestOperator : Formprivate void TestVaria

10、ble_Load(object sender, EventArgs e)int a, b = 5;char c1 = A;a = c1; /字符型转整型float x = 3;x += b; /整型转浮点型lblShow.Text = “a=“ + a; /整型转为字符串lblShow.Text += “nx=“ + x; /浮点型转为字符串【实例 2-7】using System;using System.Windows.Forms;namespace TestVariablepublic partial class TestOperator : Formprivate void TestV

11、ariable_Load(object sender, EventArgs e)int i = 25, j = 12;bool k;string result = “ i!=j的值为“ + (i != j);result += “n i!=j result += “n i!=j result += “n k = i!=j lblShow.Text = result;【实例 2-8】using System;using System.Windows.Forms;namespace TestInterfacepublic partial class TestInterface : Forminte

12、rface IStudent /声明接口string Answer();class Student : IStudent /声明类,以实现接口public int no;public string name;public string Answer()string result = “该学生信息如下:“;result += “n学号:“ + no;result += “n姓名:“ + name;return result;private void btnOk_Click(object sender, EventArgs e)Student a = new Student(); /定义并初始化变

13、量aa.no = Convert.ToInt32(txtStuID.Text);a.name = txtName.Text;lblShow.Text = a.Answer();【实例 2-9】using System;class HelloWorldpublic string HelloCN()return “你好!我是Jackson,中国人。“;public string HelloEN()return “Hi! I am Jackson, a American.“;class TestDelegatedelegate string MyDelegate(); /声明委托static voi

14、d Main(string args)HelloWorld hello = new HelloWorld(); /创建对象MyDelegate h = new MyDelegate(hello.HelloCN); /创建委托对象并指向一个方法Console.WriteLine(h(); /通过委托对象调用所指向的方法h = new MyDelegate(hello.HelloEN); Console.WriteLine(h();【实例 2-10】using System;class TestArraystatic void Main(string args)int x,y; /声明数组x =

15、new int5 1,5,3,2,4; /初始化数组y = new int5;Array.Copy(x, y, 5); /将数组x的5个元素复制到数组y中Console.WriteLine(“成功地从数组x复制到数组y,数组y各元素值如下:“);for (int i = 0; i = A j-) /j表示在第i行左边的第j个空白字符Console.Write(“ “);for (k = 0; k 2 * i + 1; k+) /k表示在第i行的第k个星号字符,Console.Write(“*“);Console.Write(“n“);【实例 2-21】using System;class Te

16、stGotostatic void Main()char c;for(int i=0;i80;i+) /最多输入80个字符c=(char)Console.Read();if(c=*) break; /一旦输入星号就结束Console.Write(c);【实例 2-22】using System;class TestContinuestatic void Main()char ch_old,ch_new;ch_old=.;Console.WriteLine(“请输入一串字符,以句号结尾:“);doch_new = (char)Console.Read();if(ch_new = ch_old)continue;Console.Write(ch_new);ch_old=ch_new;while(ch_new!=.);Console.Write(“n“);

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报