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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

最新c#实例源代码.docx

1、最新c#实例源代码【实例1-1】using System;using System.Collections.Generic;using System.Text;namespace _ class Program static 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 La

2、bel();lbShow.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 Tes

3、tEnum public 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的

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

5、public string Answer() 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.Tex

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

7、; /32位的浮点型常量 Console.WriteLine(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).Ge

8、tType(); /16位的字符型常量Console.ReadLine(); 【实例2-4】using System;class TestVariable static 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 TestVariable public partial clas

9、s TestOperator : Form private void TestVariable_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 TestVariable public partial class T

10、estOperator : Form private void TestVariable_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 TestVariable public partia

11、l class TestOperator : Form private void TestVariable_Load(object sender, EventArgs e) int i = 25, j = 12; bool k; string result = i!=j的值为 + (i != j); result += n i!=j & i=j的值为 + (i != j & i = j); result += n i!=j & i=j+20的值为 +(i != j & i = j + 20); result += n k = i!=j & i=j的值为 + (i != j & i = j);

12、lblShow.Text = result; 【实例2-8】using System;using System.Windows.Forms;namespace TestInterface public partial class TestInterface : Form interface IStudent /声明接口 string Answer(); class Student : IStudent /声明类,以实现接口 public int no; public string name; public string Answer() string result = 该学生信息如下:; re

13、sult += n学号: + no; result += n姓名: + name; return result; private void btnOk_Click(object sender, EventArgs e) Student a = new Student(); /定义并初始化变量a a.no = Convert.ToInt32(txtStuID.Text); a.name = txtName.Text; lblShow.Text = a.Answer(); 【实例2-9】using System;class HelloWorld public string HelloCN() re

14、turn 你好!我是Jackson,中国人。; public string HelloEN() return Hi! I am Jackson, a American.; class TestDelegate delegate string MyDelegate(); /声明委托 static void Main(string args) HelloWorld hello = new HelloWorld(); /创建对象 MyDelegate h = new MyDelegate(hello.HelloCN); /创建委托对象并指向一个方法 Console.WriteLine(h(); /通

15、过委托对象调用所指向的方法 h = new MyDelegate(hello.HelloEN); Console.WriteLine(h(); 【实例2-10】using System;class TestArray static void Main(string args) int x,y; /声明数组 x = 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

16、 y.Length; i+) Console.Write(0t, yi); Array.Sort(x); /将数组x的元素排序 Console.WriteLine(n经过排序后,数组x各元素值如下:); for (int i = 0; i x.Length; i+) Console.Write(0t, xi); 【实例2-11】using System;using System.Windows.Forms;using System.Text;namespace TestString public partial class TestString : Form private void Test

17、String_Load(object sender, EventArgs e) string s; /定义字符串变量 StringBuilder sb = new StringBuilder(); /创建可变字符串对象 sb.Append(北运); /添加字符串 sb.Insert(1, 京奥); /插入字符串 s = sb.ToString(); /把可变字符串对象转化为字符串 s = s.Insert(s.Length, 2008); lblShow.Text = + s + 长度为 + s.Length; 【实例2-12】using System;using System.Windows

18、.Forms;namespace TestIf public partial class TestInterface : Form private void btnOk_Click(object sender, EventArgs e) char c = Convert.ToChar(txtChar.Text); /字符串转换为字符型 if (Char.IsLetter(c) if (Char.IsLower(c) lblShow.Text = 这是一个小写字母。; else if (Char.IsUpper(c) lblShow.Text =这是大写字母。; else lblShow.Tex

19、t =这是中文字符。; else lblShow.Text =这不是语言文字。; 【实例2-13】using System;class TestSwitch static void Main() Console.WriteLine(服装类别: 1=休闲装 2=西装 3=皮衣); Console.Write(请选择类别: ); string s = Console.ReadLine(); int n = Convert.ToInt16(s); /把数字形式的字符串转化为整型数 int t,cost = 0; /t用来记录数量,cost用来记录金额 switch (n) case 1: Conso

20、le.Write(休闲装的套数:); s = Console.ReadLine(); t = Convert.ToInt16(s); cost = t * 150; break; case 2: Console.Write(西装的套数:); s = Console.ReadLine(); t = Convert.ToInt16(s); cost = t * 300; break; case 3: Console.Write(皮衣的件数:); s = Console.ReadLine(); t = Convert.ToInt16(s); cost = t * 600; break; defaul

21、t: Console.WriteLine(无效选择,请输入1、2或 3!); break; if (cost != 0) Console.WriteLine(应付款0元., cost); Console.WriteLine(谢谢您的惠顾!); 【实例2-14】using System;using System.Windows.Forms;namespace TestWhile public partial class TestWhile : Form public TestWhile() /Visual Studio .Net自动生成的构造函数 InitializeComponent(); p

22、rivate void TestWhile_Load(object sender, EventArgs e) int i,sum; i=1; /循环变量赋初值 sum=0; while(i= A & c = a & c = z) n+; while (c != n); Console.WriteLine(该行中英文字母的个数为:0, n); 【实例2-16】using System;using System.Windows.Forms;namespace TestFor public partial class TestFor : Form public TestFor() Initializ

23、eComponent(); private void TestWhile_Load(object sender, EventArgs e) int i; int t; long s1, s2; s1 = t = 1; /*百万富翁第一天给陌生人的钱为1分*/ s2 = 100000; /*陌生人第一天给百万富翁的钱为十万元*/ for (i = 2; i = 30; i+) t = t * 2; /*百万富翁第i天给陌生人的钱*/ s1 = s1 + t; /*百万富翁第i天后共给陌生人的钱*/ s2 = s2 + 100000; /*陌生人第i天后共百万富翁的钱*/ s1 = s1 / 10

24、0; /*将百分富翁给陌生人的分币换成元*/ MessageBox.Show(百万富翁给陌生人+s1+元。n陌生人给百万富翁+s2+元。 ); 【实例2-17】using System;class TestForeach static void Main() string names = new string5; Console.WriteLine(请输入五个人的姓名:); for (int i = 0; i names.Length; i+) namesi=Console.ReadLine(); Console.WriteLine(已输入的姓名如下,请核对:); foreach (strin

25、g name in names) Console.Write(0t, name); 【实例2-18】using System;class TestForeach static void Main() int i, j, k; for (i = 0; i = 0; 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 TestGoto static v

26、oid 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 TestContinue static void Main() char ch_old,ch_new; ch_old=.; Console.WriteLine(请输入一串字符,以句号结尾:); do ch_new = (char)Console.Read(); if(ch_new = ch_old) continue; Console.Write(ch_new); ch_old=ch_new; while(ch_new!=.); Console.Write(n); 2015初中地理会考试题(本试卷满分100分,考试时间60分钟)第卷 (选择题 共50分)一、选择题(下列各题的四个选项中,只有一项最符合题意。每小题2分,共50分)读图1“我国的疆域示意图”,完成13题。1、有关我国地理位置的叙述,正确的是A、北回归线穿过我国南部B、最北端在漠河,最南端在曾母暗沙C

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1