c#基礎學習雜記(二)

來源:互聯網
上載者:User

1。C#中結構體可以用new在棧裡分配結構體空間,也可以直接聲明變數就算分配空間,如

struct Point {int x; int y}

Point pt1 = new Point();

Point pt2;

這兩種方式的區別是,用new會將Point中的欄位初始化為0,而不用new則不會,在使用前還需要初始設定變數,C#規定變數初始化以後才能使用。

 

2。方法中new修飾符強制衍生類別中的方法隱藏父類的方法。如:

class B {

     public virtual void foo() { }

}

class D : B {

     public override void foo(){ }

}

class N : D {

     public new void foo() { }

}

 

3 。在.NET Framework Class Library中大概有7000多個類型,包括結構體,類,介面,枚舉以及委託。這些類型包含在大概100多個命名空間中。包括:

1).IO(File and String)

包括: BinaryReader, BinaryWriter, BufferedStream, Directory, DirectoryInfo, Path, File, FileInfo, FileStream, FileSystemInfo, MemoryStream, Stream, StreamWrite, StreamReader, TextReader, TextWriter, IOException,以及System.Net.Sockets中的類

2).Collection(Hash Tables and Dynamic Arrays)

包括: HashTable, ArrayList等

3). Regular Exception

4).Internet Classes(HttpWebRequest,

HttpWebResponse,System.WebMail)

包括:Cookie, CookieClloction, Dns, FileWebQuest, FileWebResponse等

5).Data(DataReaders, DataSets,DataAdapters)

包括:Connection, Command, DataReader, DataSet, DataAdapter等

6).Reflection 

 

4.C#中結構不支援繼承,即它不能派生於其他類或結構,也不能被其他類或結構繼承,但它可以繼承多個介面。例外的是結構總是預設派生於System.ValueType。

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.