日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

編程技巧OOPs:復(fù)制構(gòu)造函數(shù)_.Net教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:編程技巧:.Net Framework
.Net Framework 1. 如何獲得系統(tǒng)文件夾 使用System.Envioment類的GetFolderPath方法;例如: Environment.GetFolderPath( Environment.SpecialFolder.Personal ) 2. 如何獲得正在

OOPs

1. 什么是復(fù)制構(gòu)造函數(shù)

我們知道構(gòu)造函數(shù)是用來初始化我們要創(chuàng)建實例的特殊的方法。通常我們要將一個實例賦值給另外一個變量c#只是將引用賦值給了新的變量實質(zhì)上是對同一個變量的引用,那么我們怎樣才可以賦值的同時創(chuàng)建一個全新的變量而不只是對實例引用的賦值呢?我們可以使用復(fù)制構(gòu)造函數(shù)。

我們可以為類創(chuàng)造一個只用一個類型為該類型的參數(shù)的構(gòu)造函數(shù),如:

public Student(Student student)
{
this.name = student.name;
}

使用上面的構(gòu)造函數(shù)我們就可以復(fù)制一份新的實例值,而非賦值同一引用的實例了。

class Student
{
private string name;

public Student(string name)
{
this.name = name;
}
public Student(Student student)
{
this.name = student.name;
}

public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}

class Final

{

static void Main()

{

Student student = new Student ("A");

Student NewStudent = new Student (student);

student.Name = "B";

System.Console.WriteLine("The new student's name is {0}", NewStudent.Name);

}

}

The new student's name is A.

2.什么是只讀常量

就是靜態(tài)的只讀變量,它通常在靜態(tài)構(gòu)造函數(shù)中賦值。

class Numbers
{
public readonly int m;
public static readonly int n;

public Numbers (int x)
{
m=x;
}

static Numbers ()
{
n=100;
}

} //其中n就是一個只讀的常量,對于該類的所有實例他只有一種值,而m則根據(jù)實例不同而不同。

分享:存儲過程編寫經(jīng)驗和優(yōu)化措施
介紹:在數(shù)據(jù)庫的開發(fā)過程中,經(jīng)常會遇到復(fù)雜的業(yè)務(wù)邏輯和對數(shù)據(jù)庫的操作,這個時候就會用SP來封裝數(shù)據(jù)庫操作。如果項目的SP較多,書寫又沒有一定的規(guī)范,將會影響以后的系統(tǒng)維護困難和大SP邏輯

來源:模板無憂//所屬分類:.Net教程/更新時間:2008-08-22
相關(guān).Net教程