freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

xx-20xx年c核心語法總結(jié)-資料下載頁

2024-11-14 02:28本頁面

【導(dǎo)讀】段不一定是靜態(tài)的可以使用static修飾。

  

【正文】 oString() { return [ + name + + age + ]。 } } class Program { static void Main(string[] args) { A[] array =new A[3]。 array[0] = new A(李志偉 ,20)。 array[1] = new A(張三 , 19)。 array[2] = new A(李四 , 17)。 (array)。//排序方法 , 對(duì)自定義類型進(jìn)行排序 foreach(A i in array) { (i+ )。 } } } (3)為自定義的類定義排序類 (IComparer接口 ) class A { private string name。 private int age。 public A(string name, int age) { = name。 = age。 } public string Name { get { return name。 } } public int Age { get { return age。 } } public override string ToString() { return [ + name + + age + ]。 } } class B : IComparer//專為類 A設(shè)計(jì)的排序類 { private static B b。 private B() { } public static B GetB() { if (b == null) { b = new B()。 } return b。 } public int Compare(Object x, Object y)//實(shí)現(xiàn)排序方法 { A xa, ya。 if ((x is A) amp。amp。 (y is A)) { xa = x as A。 ya = y as A。 } else { throw new ArgumentException(類型不一致! )。 } return ()。//根據(jù)姓名排序 } } class Program { static void Main(string[] args) { A[] array =new A[3]。 array[0] = new A(李志偉 ,20)。 array[1] = new A(張三 , 19)。 array[2] = new A(李四 , 17)。 (array,())。//排序方法 foreach(A i in array) { (i+ )。 } } } (1)說明: 通過擴(kuò)展方法,我們可以對(duì)已有類型做自己想做的相關(guān)擴(kuò)展而不需要已有類型的源代碼。擴(kuò)展方法是通過額外的靜態(tài)方法擴(kuò)展現(xiàn)有的類型。也可以對(duì) String,Int,DataTable 等類型的基礎(chǔ)上增加一個(gè)或多個(gè)方法,使用時(shí)不需要去修改或編譯類型本身的代碼。 (2)例子: public static class MyExtensions//靜態(tài)的擴(kuò)展類 { public static int StringExtensions(this String str)//為 String類增加一個(gè)方法 { (str)。 return 。 } public static String StringJoin(this String str1,String str2)//為 String類增加一個(gè)方法 { (str1+str2)。 return str1 + str2。 } } class Program { static void Main(string[] args) { String s = 12345678。 ()。//測(cè)試自定義的擴(kuò)展方法 (000000000000000)。//測(cè)試自定義的擴(kuò)展方法 } } (3)注意: 如果擴(kuò)展方法包含參數(shù),就可以在要擴(kuò)展的類型(即第一個(gè)參數(shù))以后順序的添加擴(kuò)展方法對(duì)應(yīng)的參數(shù)既可,在調(diào)用的時(shí)候填寫相應(yīng)參數(shù),不過請(qǐng)記住,第一個(gè)參數(shù) 是 要擴(kuò)展的類型, 其前面要加 this 關(guān)鍵字, 在填寫實(shí)參的時(shí)候并沒有這個(gè)參數(shù)。 (sealed) (1)Sealed修飾類不能被繼承, sealed修飾方法不能被重寫,類似 Java的 Final關(guān)鍵字。 return 語句動(dòng)態(tài)的返回集合 class Program { static IEnumerablestring GetEnumerator(int a, int b) { long d = 1。 for (int i = 1。 i = b。 i++) { d = a * d。 yield return a + 的 + i + 次方是: + d。//多次被執(zhí)行 } } static void Main(string[] args) { foreach (string s in GetEnumerator(2,20))//遍歷返回的集合 { (s)。 } } } (1)多線程的基本使用 不需要傳遞參數(shù) ,也不需要返回參數(shù) : class Program { static void Main(string[] args) { for (int i = 0。 i 30。 i++) { ThreadStart threadStart = new ThreadStart(Calculate)。 Thread thread = new Thread(threadStart)。 ()。 } (2020)。 ()。 } public static void Calculate() { DateTime time = 。//得到當(dāng)前時(shí)間 Random ra = new Random()。//隨機(jī)數(shù)對(duì)象 ((10,100))。//隨機(jī)休眠一段時(shí)間 ( + : + )。 } } ThreadStart是一個(gè)委托,這 個(gè)委托 的 定義為 void ThreadStart(),沒有參數(shù)與返回值。 需要傳遞單個(gè)參數(shù) : class Program { static void Main(string[] args) { for (int i = 0。 i 30。 i++) { ParameterizedThreadStart tStart = new ParameterizedThreadStart(Calculate)。 Thread thread = new Thread(tStart)。 (i*10+10)。//傳遞參數(shù) } (2020)。 ()。 } public static void Calculate(object arg) { Random ra = new Random()。//隨機(jī)數(shù)對(duì)象 ((10, 100))。//隨機(jī)休眠一段時(shí)間 (arg)。 } } ParameterThreadStart 委托定義為 void ParameterizedThreadStart(object state),有一個(gè)參數(shù)但是沒有返回值。 使用專門的線程類: class Program { static void Main(string[] args) { MyThread mt = new MyThread(100)。 ThreadStart threadStart = new ThreadStart()。 Thread thread = new Thread(threadStart)。 ()。 //等待線程結(jié)束 while ( != ) { (10)。 } ()。//打印返回值 ()。 } } public class MyThread//線程類 { public int Parame { set。 get。 }//參數(shù) public int Result { set。 get。 }//返回值 //構(gòu)造函數(shù) public MyThread(int parame) { = parame。 } //線程執(zhí)行方法 public void Calculate() { Random ra = new Random()。//隨機(jī)數(shù)對(duì)象 ((10, 100))。//隨機(jī)休眠一段時(shí)間 ()。 = * (10, 100)。 } } 使用線程類可以有多個(gè)參數(shù)與多個(gè)返回值,十分靈活! 使用匿名方法: class Program { static void Main(string[] args) { int
點(diǎn)擊復(fù)制文檔內(nèi)容
黨政相關(guān)相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1