c实例源代码

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

【实例1-1】

using System;

using System、Collections、Generic;

using System、Text;

namespace _

{

class Program

{

static void Main(string[] args)

{

System、Console、Wriine("恭喜您,学会了C#编程!");

System、Console、ReadLine();

}

}

}

【实例1-2】

private void Form1_Load(object sender, EventArgs e)

{

this、Text="这就是一窗口!";

Label lbShow = new Label();

lbShow、Location = new Point(40,50);

lbShow、AutoSize = true;

lbShow、Text = "恭喜您学会编程了!";

this、Controls、Add(lbShow);

int[] x, y;

x = new int[5] { 1,2,3,4,5};

y = new int[5];

y = x;

foreach (int a in y)

{

lbShow、Text += a、ToString();

}

this、Controls、Add(lbShow);

}

【实例2-1】

using System;

using System、Windows、Forms;

namespace TestEnum

{

public partial class TestEnum : Form

{

//Visual Studio 、Net自动生成得构造函数,后文示例将全部省略

public TestEnum()

{

Initializeponent();

}

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 += (int)x; //将x转换为整数

result += "\n枚举数y代表枚举元素" + y;

lblShow、Text = result;

}

}

}

【实例2-2】

using System;

using System、Windows、Forms;

namespace Test Stru

{

public partial class TestStru : Form

{

struct Student//声明结构型

{

//声明结构型得数据成员

public int no;

public string name;

public char sex;

public int score;

//声明结构型得方法成员

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、Text = s、Answer(); //显示该生信息

lblShow、Text += "\n\n"+DateTime、Now; //显示当前时间 }

}

}

【实例2-3】

using System;

class TestConstant

{

static void Main(string[] args)

{

Console、Wriine((0)、GetType()); //有符号得32位整型常量

Console、Wriine((0U)、GetType()); //无符号得32位整型常量

Console、Wriine((0L)、GetType()); //64位得长整型常量

Console、Wriine((0F)、GetType()); //32位得浮点型常量

Console、Wriine((0D)、GetType()); //64位得双精度型常量

Console、Wriine((0M)、GetType()); //128位得小数型常量

Console、Wriine(('0')、GetType()); //16位得字符型常量

Console、Wriine(("0")、GetType()); //字符串常量

Console、Wriine((0、0)、GetType()); //64位得双精度型常量

Console、Wriine((true)、GetType()); //布尔型常量

Console、Wriine(('\u0041')、GetType()); //16位得字符型常量

Console、ReadLine();

}

}

【实例2-4】

相关文档
最新文档