预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共35页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

第二讲C#程序基础2.1简单的C#程序及其构成 2.2C#程序中的基本输入输出 2.3C#中的数据类型 2.1简单的C#程序及其构成2.1.1第一个C#程序例2、简单窗口程序 usingSystem; usingSystem.Drawing; usingSystem.Windows.Forms publicclassHelloWorldForm:System.Windows.Forms.Form {publicHelloWorldForm() {this.ClientSize=newSystem.Drawing.Size(200,180); this.Name="HelloWorldForm"; this.Text="HelloWorldForm"; this.Paint+=newSystem.Windows.Forms.PaintEventHandler( this.HelloWorldForm_Paint); }staticvoidMain() {Application.Run(newHelloWorldForm()); } privatevoidHelloWorldForm_Paint(objectsender, System.Windows.Forms.PaintEventArgse) {e.Graphics.DrawString("Hello,world", newFont("CuriorNew",12f), newSolidBrush(Color.Blue), 50f,100f,null); } }例3、另一个简单的窗口程序 usingSystem; usingSystem.Drawing; usingSystem.Windows.Forms; namespacech01 {publicclassHelloWorldWin:System.Windows.Forms.Form {publicHelloWorldWin(){InitializeComponent();} privatevoidInitializeComponent() {this.ClientSize=newSystem.Drawing.Size(200,180); this.Name="HelloWorldWin";this.Text="HelloWorldWin"; this.Paint+=newSystem.Windows.Forms.PaintEventHandler( this.HelloWorldWin_Paint);}staticvoidMain() {Application.Run(newHelloWorldWin()); } privatevoidHelloWorldWin_Paint(objectsender, System.Windows.Forms.PaintEventArgse) {e.Graphics.DrawString("Hello,world", newFont("CuriorNew",12f), newSolidBrush(Color.Blue), 50f,100f,null); }}}2.1.2C#程序结构概括2.1.3名称空间(名字空间)2.1.4using语句的使用嵌套的名称空间2.1.5Main方法如第一章的helloworld程序可以改写如下,在运行程序时需要 一个命令行参数,并在程序中显示这一参数的值。 usingSystem; classHello { staticvoidMain(string[]args){ Console.WriteLine("Hello,World"+args[0]); } } 2.1.6C#中的其他特定成分对象索引就是属性数组,利用下标来取得对象的属性数据。同样用get和set来表达,但与属性不同的是,索引没有名字,在定义时直接用this表示,在使用时,用“[下标]”来表示。 指代(又叫代理或委派)是用来指代函数的,可以理解为一种类型安全的、面向对象的函数指针。 C#直接使用delegate和event关键字来解决事件问题。2.2C#程序中的基本输入输出 usingSystem; publicclassCharInandOut {publicstaticvoidMain(string[]args) {charc=''; System.Console.Write("Pleaseinputachar:"); c=(char)System.Console.Read(); Console.WriteLine("youhaveentered:"+c); } } usingSystem; publicclassLineInandOut {publicstaticvoidMain(s