C#相關(guān)試習(xí)題_第1頁
C#相關(guān)試習(xí)題_第2頁
C#相關(guān)試習(xí)題_第3頁
C#相關(guān)試習(xí)題_第4頁
C#相關(guān)試習(xí)題_第5頁
已閱讀5頁,還剩24頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、1. 傳入某個(gè)屬性的set方法的隱含參數(shù)的名稱是什么value,它的類型和屬性所聲名的類型相同。 2. 如何在C#中實(shí)現(xiàn)繼承在類名后加上一個(gè)冒號,再加上基類的名稱。 3. C#支持多重繼承么不支持??梢杂媒涌趤韺?shí)現(xiàn)。 4. 被protected修飾的屬性/方法在何處可以訪問在繼承或間接繼承與這個(gè)類的子類中可以訪問。 5. 私有成員會被繼承么會,但是不能被訪問。所以看上去他們似乎是不能被繼承的,但實(shí)際上確實(shí)被繼承了。 6. 請描述一下修飾符protected internal。 被protected internal修飾的屬性/方法只能

2、在它的在同一個(gè)程序集(Assembly)中的子類被訪問。 7. C#提供一個(gè)默認(rèn)的無參數(shù)構(gòu)造函數(shù),當(dāng)我實(shí)現(xiàn)了另外一個(gè)有一個(gè)參數(shù)的構(gòu)造函數(shù)時(shí)候,還想保留這個(gè)無參數(shù)的構(gòu)造函數(shù)。這樣我應(yīng)該寫幾個(gè)構(gòu)造函數(shù)兩個(gè),一旦你實(shí)現(xiàn)了一個(gè)構(gòu)造函數(shù),C#就不會再提供默認(rèn)的構(gòu)造函數(shù)了,所以需要手動實(shí)現(xiàn)那個(gè)無參數(shù)構(gòu)造函數(shù)。 8. C#中所有對象共同的基類是什么System.Object. 9. 重載和覆寫有什么區(qū)別重載提供了對一個(gè)方法簽名的不同參數(shù)調(diào)用的實(shí)現(xiàn)。覆寫提供了子類中改變父類方法行為的實(shí)現(xiàn)。 10. 在方法定義中,virtual有什么含意 被virtual修飾的方法可以被

3、子類覆寫。 11. 能夠?qū)⒎庆o態(tài)的方法覆寫成靜態(tài)方法么不能,覆寫方法的簽名必須與被覆寫方法的簽名保持一致,除了將virtual改為override。 12. 可以覆寫私有的虛方法么不可以,甚至子類中無法訪問父類中的私有方法。 13. 能夠阻止某一個(gè)類被其他類繼承么 可以,使用關(guān)鍵字sealed。 14. 能夠?qū)崿F(xiàn)允許某個(gè)類被繼承,但不允許其中的某個(gè)方法被覆寫么 可以,標(biāo)記這個(gè)類為public,并標(biāo)記這個(gè)方法為sealed。 15. 什么是抽象類(abstract class)一種不可以被實(shí)例化的類。抽象類中一般含有抽象方法,當(dāng)然也可有具體實(shí)現(xiàn)。

4、繼承類只有實(shí)現(xiàn)過所有抽象類的抽象方法后才能被實(shí)例化。 16. 何時(shí)必須聲明一個(gè)類為抽象類 當(dāng)這個(gè)類中包含抽象方法時(shí),或是該類并沒有完全實(shí)現(xiàn)父類的抽象方法時(shí)。 17. 接口(interface)是什么只含有共有抽象方法(public abstract method)的類。這些方法必須在子類中被實(shí)現(xiàn)。 18. 為什么不能指定接口中方法的修飾符 接口中的方法用來定義對象之間通信的契約,指定接口中的方法為私有或保護(hù)沒有意義。他們默認(rèn)為公有方法。 19. 可以繼承多個(gè)接口么 當(dāng)然。 20. 那么如果這些接口中有重復(fù)的方法名稱呢 這種情況中你可以決定如何實(shí)

5、現(xiàn)。當(dāng)然需要特別得小心。但是在編譯環(huán)節(jié)是沒有問題的。 21. 接口和抽象類的區(qū)別是什么 接口中所有方法必須是抽象的,并且不能指定方法的訪問修飾符。抽象類中可以有方法的實(shí)現(xiàn),也可以指定方法的訪問修飾符。 22. 如何區(qū)別重載方法 不同的參數(shù)類型,不同的參數(shù)個(gè)數(shù),不同的參數(shù)順序。 23. const和readonly有什么區(qū)別const關(guān)鍵字用來聲明編譯時(shí)常量,readonly用來聲明運(yùn)行時(shí)常量。 24. System.String 和System.StringBuilder有什么區(qū)別System.String是不可變的字符串。System.StringBu

6、ilder存放了一個(gè)可變的字符串,并提供一些對這個(gè)字符串修改的方法。 1.靜態(tài)成員和非靜態(tài)成員的區(qū)別2.const 和 static readonly 區(qū)別3.extern 是什么意思4.abstract 是什么意思5.internal 修飾符起什么作用6.sealed 修飾符是干什么的7.override 和 overload 的區(qū)別8.什么是索引指示器9.new 修飾符是起什么作用10.this 關(guān)鍵字的含義11.可以使用抽象函數(shù)重寫基類中的虛函數(shù)嗎12.密封類可以有虛函數(shù)嗎13.什么是屬性訪問器14.abstract 可以和 virtual 一起使用嗎可以和 override 一起使用嗎

7、15.接口可以包含哪些成員16.類和結(jié)構(gòu)的區(qū)別17.接口的多繼承會帶來哪些問題18.抽象類和接口的區(qū)別19.別名指示符是什么20.如何手工釋放資源21.P/Invoke是什么22.StringBuilder 和 String 的區(qū)別23.explicit 和 implicit 的含義24.params 有什么用25.什么是反射 以下是我做的一份參考答案(C# 語言范疇之內(nèi)),如果有不準(zhǔn)確、不全面的,歡迎各位朋友指正! 1.靜態(tài)成員和非靜態(tài)成員的區(qū)別?答:靜態(tài)變量使用 static 修飾符進(jìn)行聲明,在類被實(shí)例化時(shí)創(chuàng)建,通過類進(jìn)行訪問不帶有 static 修飾符聲明的變量稱做非靜態(tài)變量,

8、在對象被實(shí)例化時(shí)創(chuàng)建,通過對象進(jìn)行訪問一個(gè)類的所有實(shí)例的同一靜態(tài)變量都是同一個(gè)值,同一個(gè)類的不同實(shí)例的同一非靜態(tài)變量可以是不同的值靜態(tài)函數(shù)的實(shí)現(xiàn)里不能使用非靜態(tài)成員,如非靜態(tài)變量、非靜態(tài)函數(shù)等示例:using System;using System.Collections.Generic;using System.Text; namespace Example01    class Program            class Class1 

9、                   public static String staticStr = "Class"            public String notstaticStr = "Obj"      

10、;          static void Main(string args)                    /靜態(tài)變量通過類進(jìn)行訪問,該類所有實(shí)例的同一靜態(tài)變量都是同一個(gè)值            Console.Wri

11、teLine("Class1's staticStr: 0", Class1.staticStr);             Class1 tmpObj1 = new Class1();            tmpObj1.notstaticStr = "tmpObj1"    

12、        Class1 tmpObj2 = new Class1();            tmpObj2.notstaticStr = "tmpObj2"             /非靜態(tài)變量通過對象進(jìn)行訪問,不同對象的同一非靜態(tài)變量可以有不同的值  

13、;          Console.WriteLine("tmpObj1's notstaticStr: 0", tmpObj1.notstaticStr);            Console.WriteLine("tmpObj2's notstaticStr: 0", tmpObj2.notstaticStr);  

14、;           Console.ReadLine();            結(jié)果:Class1's staticStr: ClasstmpObj1's notstaticStr: tmpObj1tmpObj2's notstaticStr: tmpObj22.const 和 static readonly 區(qū)別?答:const用 const 修飾符聲明的成員叫常量

15、,是在編譯期初始化并嵌入到客戶端程序static readonly用 static readonly 修飾符聲明的成員依然是變量,只不過具有和常量類似的使用方法:通過類進(jìn)行訪問、初始化后不可以修改。但與常量不同的是這種變量是在運(yùn)行期初始化示例:測試類:using System;using System.Collections.Generic;using System.Text; namespace Example02Lib    public class Class1        &

16、#160;   public const String strConst = "Const"        public static readonly String strStaticReadonly = "StaticReadonly"        /public const String strConst = "Const Changed"  

17、60;     /public static readonly String strStaticReadonly = "StaticReadonly Changed"     客戶端代碼:using System;using System.Collections.Generic;using System.Text;using Example02Lib; namespace Example02    class Program  

18、0;         static void Main(string args)                    /修改Example02中Class1的strConst初始值后,只編譯Example02Lib項(xiàng)目           

19、; /然后到資源管理器里把新編譯的Example02Lib.dll拷貝Example02.exe所在的目錄,執(zhí)行Example02.exe            /切不可在IDE里直接調(diào)試運(yùn)行因?yàn)檫@會重新編譯整個(gè)解決方案!             /可以看到strConst的輸出沒有改變,而strStaticReadonly的輸出已經(jīng)改變  

20、60;         /表明Const變量是在編譯期初始化并嵌入到客戶端程序,而StaticReadonly是在運(yùn)行時(shí)初始化的            Console.WriteLine("strConst : 0", Class1.strConst);            C

21、onsole.WriteLine("strStaticReadonly : 0", Class1.strStaticReadonly);             Console.ReadLine();            結(jié)果:strConst : ConststrStaticReadonly : StaticReadonly 修改后的示例:測試類:usi

22、ng System;using System.Collections.Generic;using System.Text; namespace Example02Lib    public class Class1            /public const String strConst = "Const"        /public static read

23、only String strStaticReadonly = "StaticReadonly"        public const String strConst = "Const Changed"        public static readonly String strStaticReadonly = "StaticReadonly Changed"  

24、0; 結(jié)果strConst : ConststrStaticReadonly : StaticReadonly Changed3.extern 是什么意思?答:extern 修飾符用于聲明由程序集外部實(shí)現(xiàn)的成員函數(shù)經(jīng)常用于系統(tǒng)API函數(shù)的調(diào)用(通過 DllImport )。注意,和DllImport一起使用時(shí)要加上 static 修飾符也可以用于對于同一程序集不同版本組件的調(diào)用(用 extern 聲明別名)不能與 abstract 修飾符同時(shí)使用示例:using System;using System.Collections.Generic;using System.Text;using Sy

25、stem.Runtime.InteropServices; namespace Example03    class Program            /注意DllImport是一個(gè)Attribute Property,在System.Runtime.InteropServices命名空間中定義        /extern與DllImport一起使用時(shí)必須再加上一個(gè)static修飾

26、符        DllImport("User32.dll")        public static extern int MessageBox(int Handle, string Message, string Caption, int Type);         static int Main()    

27、                string myString;            Console.Write("Enter your message: ");            myString = Conso

28、le.ReadLine();            return MessageBox(0, myString, "My Message Box", 0);            結(jié)果: 4.abstract 是什么意思?答:abstract 修飾符可以用于類、方法、屬性、事件和索引指示器(indexer),表示其為抽象成員abstract 不可以和 sta

29、tic 、virtual 一起使用聲明為 abstract 成員可以不包括實(shí)現(xiàn)代碼,但只要類中還有未實(shí)現(xiàn)的抽象成員(即抽象類),那么它的對象就不能被實(shí)例化,通常用于強(qiáng)制繼承類必須實(shí)現(xiàn)某一成員示例:using System;using System.Collections.Generic;using System.Text; namespace Example04    #region 基類,抽象類    public abstract class BaseClass      

30、;      /抽象屬性,同時(shí)具有g(shù)et和set訪問器表示繼承類必須將該屬性實(shí)現(xiàn)為可讀寫        public abstract String Attribute                    get;       

31、     set;                 /抽象方法,傳入一個(gè)字符串參數(shù)無返回值        public abstract void Function(String value);         /抽象事件,類型為系統(tǒng)預(yù)定義的代理(delega

32、te):EventHandler        public abstract event EventHandler Event;         /抽象索引指示器,只具有g(shù)et訪問器表示繼承類必須將該索引指示器實(shí)現(xiàn)為只讀        public abstract Char thisint Index      &

33、#160;             get;                #endregion     #region 繼承類    public class DeriveClass : BaseClass       

34、0;    private String attribute;         public override String Attribute                    get          

35、                  return attribute;                        set        

36、                    attribute = value;                            public override voi

37、d Function(String value)                    attribute = value;            if (Event != null)          

38、60;                 Event(this, new EventArgs();                            public override event Ev

39、entHandler Event;        public override Char thisint Index                    get                &#

40、160;           return attributeIndex;                            #endregion     class Program   

41、;         static void OnFunction(object sender, EventArgs e)                    for (int i = 0; i < (DeriveClass)sender).Attribute.Length; i+)     

42、                       Console.WriteLine(DeriveClass)sender)i);                       

43、0;    static void Main(string args)                    DeriveClass tmpObj = new DeriveClass();             tmpObj.Attribute = "123

44、4567"            Console.WriteLine(tmpObj.Attribute);             /將靜態(tài)函數(shù)OnFunction與tmpObj對象的Event事件進(jìn)行關(guān)聯(lián)            tmpObj.Eve

45、nt += new EventHandler(OnFunction);             tmpObj.Function("7654321");             Console.ReadLine();            結(jié)

46、果:12345677654321 5.internal 修飾符起什么作用?答:internal 修飾符可以用于類型或成員,使用該修飾符聲明的類型或成員只能在同一程集內(nèi)訪問接口的成員不能使用 internal 修飾符值得注意的是,如果為 internal 成員加上了 protected 修飾符,這時(shí)的訪問級別為 internal 或 protected。只是看字面意思容易弄錯(cuò),許多人認(rèn)為 internal protected 應(yīng)該是“只有同一個(gè)程序集中的子類可以訪問”,但其實(shí)它表示“同一個(gè)程序集中的所有類,以及所有程序集中的子類都可以訪問”示例Example05Lib 項(xiàng)目的 Class1 us

47、ing System;using System.Collections.Generic;using System.Text; namespace Example05Lib    public class Class1            internal String strInternal = null;        public String strPublic; &#

48、160;      internal protected String strInternalProtected = null;    結(jié)果Example05Lib 項(xiàng)目的 Class2 類可以訪問到 Class1 的 strInternal 成員,當(dāng)然也可以訪問到 strInternalProtected 成員,因?yàn)樗麄冊谕粋€(gè)程序集里 Example05 項(xiàng)目里的 Class3 類無法訪問到 Class1 的 strInternal 成員,因?yàn)樗鼈儾辉谕粋€(gè)程序集里。但卻可以訪問到 strIntern

49、alProtected 成員,因?yàn)?Class3 是 Class1 的繼承類 Example05 項(xiàng)目的 Program 類既無法訪問到 Class1 的 strInternal 成員,也無法訪問到 strInternalProtected 成員,因?yàn)樗鼈兗炔辉谕粋€(gè)程序集里也不存在繼承關(guān)系 6.sealed 修飾符是干什么的?答:sealed 修飾符表示密封用于類時(shí),表示該類不能再被繼承,不能和 abstract 同時(shí)使用,因?yàn)檫@兩個(gè)修飾符在含義上互相排斥用于方法和屬性時(shí),表示該方法或?qū)傩圆荒茉俦恢貙?,必須?override 關(guān)鍵字一起使用,因?yàn)槭褂?sealed 修飾

50、符的方法或?qū)傩钥隙ㄊ腔愔邢鄳?yīng)的虛成員通常用于實(shí)現(xiàn)第三方類庫時(shí)不想被客戶端繼承,或用于沒有必要再繼承的類以防止濫用繼承造成層次結(jié)構(gòu)體系混亂恰當(dāng)?shù)睦?sealed 修飾符也可以提高一定的運(yùn)行效率,因?yàn)椴挥每紤]繼承類會重寫該成員示例:using System;using System.Collections.Generic;using System.Text; namespace Example06    class Program            c

51、lass A                    public virtual void F()                            Con

52、sole.WriteLine("A.F");                        public virtual void G()                   &#

53、160;        Console.WriteLine("A.G");                            class B : A          

54、;          public sealed override void F()                            Console.WriteLine("B.F");   &#

55、160;                    public override void G()                            Cons

56、ole.WriteLine("B.G");                            class C : B                  &#

57、160; public override void G()                            Console.WriteLine("C.G");              

58、;              static void Main(string args)                    new A().F();            new A()

59、.G();            new B().F();            new B().G();            new C().F();         

60、0;  new C().G();             Console.ReadLine();            結(jié)果:類 B 在繼承類 A 時(shí)可以重寫兩個(gè)虛函數(shù),如圖所示: 由于類 B 中對 F 方法進(jìn)行了密封, 類 C 在繼承類 B 時(shí)只能重寫一個(gè)函數(shù),如圖所示: 控制臺輸出結(jié)果,類 C 的方法 F 只能是輸出 類B 中對該方法的實(shí)現(xiàn):A

61、.FA.GB.FB.GB.FC.G 7.override 和 overload 的區(qū)別?答:override 表示重寫,用于繼承類對基類中虛成員的實(shí)現(xiàn)overload 表示重載,用于同一個(gè)類中同名方法不同參數(shù)(包括類型不同或個(gè)數(shù)不同)的實(shí)現(xiàn)示例:using System;using System.Collections.Generic;using System.Text; namespace Example07    class Program          &

62、#160; class BaseClass                    public virtual void F()                         &

63、#160;  Console.WriteLine("BaseClass.F");                            class DeriveClass : BaseClass           &#

64、160;        public override void F()                            base.F();          &#

65、160;     Console.WriteLine("DeriveClass.F");                        public void Add(int Left, int Right)         &#

66、160;                  Console.WriteLine("Add for Int: 0", Left + Right);                        publ

67、ic void Add(double Left, double Right)                            Console.WriteLine("Add for int: 0", Left + Right);       &#

68、160;                    static void Main(string args)                    DeriveClass tmpObj = new DeriveClass();  &

69、#160;         tmpObj.F();            tmpObj.Add(1, 2);            tmpObj.Add(1.1, 2.2);          

70、60;  Console.ReadLine();            結(jié)果:BaseClass.FDeriveClass.FAdd for Int: 3Add for int: 3.3 8.什么是索引指示器?答:實(shí)現(xiàn)索引指示器(indexer)的類可以象數(shù)組那樣使用其實(shí)例后的對象,但與數(shù)組不同的是索引指示器的參數(shù)類型不僅限于int簡單來說,其本質(zhì)就是一個(gè)含參數(shù)屬性示例: using System;using System.Collections.Generic;using Syste

71、m.Text; namespace Example08    public class Point            private double x, y;        public Point(double X, double Y)             &

72、#160;      x = X;            y = Y;                /重寫ToString方法方便輸出        public override string ToString() 

73、                   return String.Format("X: 0 , Y: 1", x, y);                public class Points        &

74、#160;   Point points;        public Points(Point Points)                    points = Points;             

75、   public int PointNumber                    get                           

76、  return points.Length;                                 /實(shí)現(xiàn)索引訪問器        public Point thisint Index   

77、0;                get                            return pointsIndex;     &#

78、160;                       /感謝watson hua(    /索引指示器的實(shí)質(zhì)是含參屬性,參數(shù)并不只限于int    class WeatherOfWeek            public string thisin

79、t Index                    get                            /注意case段使用return直接返回所以

80、不需要break                switch (Index)                                

81、    case 0:                                              

82、60;     return "Today is cloudy!"                                        &#

83、160;   case 5:                                               

84、;     return "Today is thundershower!"                                       

85、60;    default:                                              

86、;      return "Today is fine!"                                         

87、;                           public string thisstring Day                    get  

88、;                          string TodayWeather = null;                /switch的標(biāo)準(zhǔn)寫法    

89、;            switch (Day)                                    case "Sun

90、day":                                                 &

91、#160;  TodayWeather = "Today is cloudy!"                            break;            

92、0;                               case "Friday":                &#

93、160;                                   TodayWeather = "Today is thundershower!"       

94、0;                    break;                              &#

95、160;             default:                                    

96、0;               TodayWeather = "Today is fine!"                            break;

97、60;                                                   &

98、#160;   return TodayWeather;                            class Program            static void Main(string args) 

99、0;                  Point tmpPoints = new Point10;            for (int i = 0; i < tmpPoints.Length; i+)          

100、;                  tmpPointsi = new Point(i, Math.Sin(i);                         Points tmpObj = new Poi

101、nts(tmpPoints);            for (int i = 0; i < tmpObj.PointNumber; i+)                            Console.WriteL

102、ine(tmpObji);                          string Week = new string "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Frid

103、ay", "Staurday"            WeatherOfWeek tmpWeatherOfWeek = new WeatherOfWeek();            for (int i = 0; i < 6; i+)         

104、                   Console.WriteLine(tmpWeatherOfWeeki);                        foreach (string tmpDay in

105、 Week)                            Console.WriteLine(tmpWeatherOfWeektmpDay);                

106、60;        Console.ReadLine();            結(jié)果:X: 0 , Y: 0X: 1 , Y: 0.84X: 2 , Y: 0.6825682X: 3 , Y: 0.67X: 4 , Y: -0.5307928X: 5 , Y: -0.4663138X: 6 , Y: -0.2794X: 7 , Y: 0.8718789X: 8 , Y: 0.6623382X: 9 , Y: 0.47Tod

107、ay is cloudy!Today is fine!Today is fine!Today is fine!Today is fine!Today is thundershower!Today is cloudy!Today is fine!Today is fine!Today is fine!Today is fine!Today is thundershower!Today is fine! 9.new 修飾符是起什么作用?答:new 修飾符與 new 操作符是兩個(gè)概念new 修飾符用于聲明類或類的成員,表示隱藏了基類中同名的成員。而new 操作符用于實(shí)例化一個(gè)類型new 修

108、飾符只能用于繼承類,一般用于彌補(bǔ)基類設(shè)計(jì)的不足new 修飾符和 override 修飾符不可同時(shí)用在一個(gè)成員上,因?yàn)檫@兩個(gè)修飾符在含義上互相排斥示例:using System;using System.Collections.Generic;using System.Text; namespace Example09    class BaseClass            /基類設(shè)計(jì)者聲明了一個(gè)PI的公共變量,方便進(jìn)行運(yùn)算  

109、60;     public static double PI = 3.1415;        class DervieClass : BaseClass            /繼承類發(fā)現(xiàn)該變量的值不能滿足運(yùn)算精度,于是可以通過new修飾符顯式隱藏基類中的聲明        public new static double

110、PI = 3.1415926;        class Program            static void Main(string args)                    Console.WriteLine(BaseClass.PI);&

111、#160;           Console.WriteLine(DervieClass.PI);             Console.ReadLine();            結(jié)果:3.14153.1415926 10.this 關(guān)鍵字的含義?答:this 是一個(gè)保留

112、字,僅限于構(gòu)造函數(shù)和方法成員中使用在類的構(gòu)造函數(shù)中出現(xiàn)表示對正在構(gòu)造的對象本身的引用,在類的方法中出現(xiàn)表示對調(diào)用該方法的對象的引用,在結(jié)構(gòu)的構(gòu)造上函數(shù)中出現(xiàn)表示對正在構(gòu)造的結(jié)構(gòu)的引用,在結(jié)構(gòu)的方法中出現(xiàn)表示對調(diào)用該方法的結(jié)果的引用this 保留字不能用于靜態(tài)成員的實(shí)現(xiàn)里,因?yàn)檫@時(shí)對象或結(jié)構(gòu)并未實(shí)例化在 C# 系統(tǒng)中,this 實(shí)際上是一個(gè)常量,所以不能使用 this+ 這樣的運(yùn)算this 保留字一般用于限定同名的隱藏成員、將對象本身做為參數(shù)、聲明索引訪問器、判斷傳入?yún)?shù)的對象是否為本身示例:using System;using System.Collections.Generic;using

113、System.Text; namespace Example10    class Class1            private double c;        private string value;         public double C    &

114、#160;               get                            return c;       

115、60;                    public Class1(double c)                    /限定同名的隱藏成員        &

116、#160;   this.c = c;                public Class1(Class1 value)                    /用對象本身實(shí)例化自己沒有意義     

117、60;      if (this != value)                            c = value.C;              

118、;              public override string ToString()                    /將對象本身做為參數(shù)            retur

119、n string.Format("0 Celsius = 1 Fahrenheit", c, UnitTransClass.C2F(this);                 /由于好奇,在這做了一個(gè)效率測試,想看看到底哪種方式訪問成員變量更快,結(jié)論:區(qū)別不大。        public string Test1()   &

120、#160;                long vTickCount = Environment.TickCount;            for (int i = 0; i < ; i+)            &#

121、160;   this.value = i.ToString();            return string.Format("Have this.: 0 MSEL", Environment.TickCount - vTickCount);                public string T

122、est2()                    long vTickCount = Environment.TickCount;            for (int i = 0; i < ; i+)        &

123、#160;       value = i.ToString();            return string.Format("Don't have this.: 0 MSEL", Environment.TickCount - vTickCount);                class UnitTransClass            public static double C2F(Class1 value)                    /攝氏到華氏的轉(zhuǎn)換公式 

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論