国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

Whidbey 初體驗(yàn)之局部類型 ( partial 類型)

2024-07-21 02:17:06
字體:
供稿:網(wǎng)友


whidbey 初體驗(yàn) 之 局部類型 ( partial 類型)
visual studio 2005 [whidbey] 搶先體驗(yàn)版 [express beta 1 ] 出來有一段時(shí)間了,并且在微軟的官方網(wǎng)站上有免費(fèi)的下載(下載地址:http://lab.msdn.microsoft.com/vs2005/)。就本人而言是非常喜歡c#這一新生的語言的。也許并不能說它是新生的,它是對(duì)以往各種語言的提煉,或許它是站在巨人的肩膀上的,所以才顯得如此的優(yōu)秀。伴隨體驗(yàn)版而來的c# 2.0 給我們帶來了新的語言特性(generics:泛型; iterators:迭代; partial classes:局部類型; anonymous methods:匿名方法;),使我們能更容易的編寫出簡潔明快的代碼,當(dāng)然這些新特性給我們帶來的遠(yuǎn)不止簡潔明快的代碼。這只有在我們使用的過程中自己體會(huì)和別人的交流中了解。

分別用2003和2005 新建兩個(gè)windowsapplication1
2003和2005解決方案資源管理器中都會(huì)默認(rèn)建立一個(gè)從system.windows.forms.form 類繼承的窗體類form1
那我們比較下兩個(gè)不同的ide環(huán)境為我們自動(dòng)生成的form1的代碼是怎么樣的。
選中form1.cs察看代碼
2003:
public class form1 : system.windows.forms.form
{
private system.windows.forms.button button1;
/// <summary>
/// 必需的設(shè)計(jì)器變量。
/// </summary>
private system.componentmodel.container components = null;

public form1()
{
//
// windows 窗體設(shè)計(jì)器支持所必需的
//
initializecomponent();
//
// todo: 在 initializecomponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
}

/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}

#region windows 窗體設(shè)計(jì)器生成的代碼
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void initializecomponent()
{
this.button1 = new system.windows.forms.button();
this.suspendlayout();
//
// button1
//
this.button1.location = new system.drawing.point(88, 72);
this.button1.name = "button1";
this.button1.size = new system.drawing.size(72, 32);
this.button1.tabindex = 0;
this.button1.text = "button1";
this.button1.click += new system.eventhandler(this.button1_click);
//
// form1
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(292, 273);
this.controls.add(this.button1);
this.name = "form1";
this.text = "form1";
this.resumelayout(false);

}
#endregion

/// <summary>
/// 應(yīng)用程序的主入口點(diǎn)。
/// </summary>
[stathread]
static void main()
{
application.run(new form1());
}



private void button1_click(object sender, system.eventargs e)
{

}
}
2005:
partial class form1 : form
{
public form1()
{
initializecomponent();
}

private void button1_click(object sender, eventargs e)
{

}
}
察看兩個(gè)環(huán)境下form1的代碼文件 form1.cs文件里對(duì)form1的代碼差別很大,2005中只有那么一點(diǎn)點(diǎn),對(duì)button1的定義沒有,click事件委托也沒有只有一個(gè)button1_click()顯然是有問題的。如果而且我們很快發(fā)現(xiàn)class form1是被定義成 partial 的也就是c# 2.0種的新的語言特征 局部類型。然后我們?cè)冱c(diǎn)一下2005 ide 解決方案資源管理器上的show all files按鈕,會(huì)發(fā)現(xiàn)form1.cs下多了個(gè)文件 form1.designer.cs 這是2003環(huán)境下是沒有的, 察看該文件我們會(huì)發(fā)現(xiàn)對(duì)class form1的另一部份定義。

partial class form1
{
/// <summary>
/// required designer variable.
/// </summary>
private system.componentmodel.icontainer components = null;

/// <summary>
/// clean up any resources being used.
/// </summary>
protected override void dispose(bool disposing)
{
if (disposing && (components != null))
{
components.dispose();
}
base.dispose(disposing);
}

#region windows form designer generated code

/// <summary>
/// required method for designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void initializecomponent()
{
this.button1 = new system.windows.forms.button();
this.suspendlayout();
//
// button1
//
this.button1.location = new system.drawing.point(75, 49);
this.button1.name = "button1";
this.button1.size = new system.drawing.size(96, 46);
this.button1.tabindex = 0;
this.button1.text = "button1";
this.button1.click += new system.eventhandler(this.button1_click);
//
// form1
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(292, 273);
this.controls.add(this.button1);
this.name = "form1";
this.text = "form1";
this.resumelayout(false);

}

#endregion

private system.windows.forms.button button1;
}
現(xiàn)在好像2005對(duì)form1的描述好像全了,2005中form1.cs 和 form1.designer.cs 兩個(gè)文件中對(duì)class form1的描述相加 就是 2003 form1.cs 中對(duì)class form1的描述。由此看來 partial 類型可以使我們把對(duì)某個(gè)類的描述寫在不同地方,甚至寫到兩個(gè)或多個(gè)不同的文件中去。partial 信息只對(duì)編譯器有用,編譯器在編譯時(shí)看到對(duì)某個(gè)類的描述是“碎”的(partial 的),它會(huì)去其他地方收集該類的其他碎片,然后把所有的該類的碎片組合成完整的一個(gè)類,再對(duì)其編譯。所以partial 體現(xiàn)不到編譯好的 il中去的。至于partial類型給我們帶來怎么樣的意義呢?我們以后再討論。

#結(jié)束
qq:14754875
email:[email protected]
bbs:www.shixm.com/bbs


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 井陉县| 兴国县| 迁安市| 开封市| 剑川县| 黑水县| 开阳县| 新民市| 铜川市| 绩溪县| 城口县| 新源县| 嘉荫县| 漠河县| 宜昌市| 永昌县| 周至县| 保靖县| 恩施市| 海门市| 高邑县| 石渠县| 内乡县| 浦江县| 寿阳县| 卓资县| 旺苍县| 同心县| 建德市| 江津市| 景泰县| 景德镇市| 屏东县| 偏关县| 姜堰市| 黄石市| 谢通门县| 康马县| 稷山县| 玉林市| 绥化市|