日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#基礎(chǔ)概念學(xué)習(xí)筆記

C#基礎(chǔ)概念之extern 是什么意思?

創(chuàng)新互聯(lián)公司長期為1000+客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為雙清企業(yè)提供專業(yè)的成都做網(wǎng)站、成都網(wǎng)站制作,雙清網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。

extern 修飾符用于聲明由程序集外部實(shí)現(xiàn)的成員函數(shù),經(jīng)常用于系統(tǒng)API函數(shù)的調(diào)用(通過 DllImport )。注意,和DllImport一起使用時(shí)要加上 static 修飾符,也可以用于對(duì)于同一程序集不同版本組件的調(diào)用(用 extern 聲明別名),不能與 abstract 修飾符同時(shí)使用。

示例:

 
 
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Runtime.InteropServices;  
  5.  
  6. namespace Example03 {   
  7. class Program {   
  8. //注意DllImport是一個(gè)Attribute Property,
    在System.Runtime.InteropServices命名空間中定義  
  9. //extern與DllImport一起使用時(shí)必須再加上一個(gè)static修飾符[DllImport("User32.dll")]   
  10. public static extern int MessageBox
    (int Handle, string Message, string Caption, int Type);  
  11.  
  12. static int Main(){   
  13. string myString;  
  14. Console.Write("Enter your message: ");  
  15. myString = Console.ReadLine();  
  16. return MessageBox(0, myString, "My Message Box", 0);  

C#基礎(chǔ)概念之a(chǎn)bstract 是什么意思?

abstract 修飾符可以用于類、方法、屬性、事件和索引指示器(indexer),表示其為抽象成員,abstract 不可以和 static 、virtual 、override 一起使用,聲明為 abstract 成員可以不包括實(shí)現(xiàn)代碼,但只有類中還有未實(shí)現(xiàn)的抽象成員,該類就不可以被實(shí)例化,通常用于強(qiáng)制繼承類必須實(shí)現(xiàn)某一成員

示例:

 
 
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4.  
  5. namespace Example04 {   
  6.  
  7. public abstract class BaseClass {   
  8. //抽象屬性,同時(shí)具有g(shù)et和set訪問器表示繼承類必須將該屬性實(shí)現(xiàn)為可讀寫  
  9. public abstract String Attribute {   
  10. get;  
  11. set;  
  12. }  
  13.  
  14. //抽象方法,傳入一個(gè)字符串參數(shù)無返回值  
  15. public abstract void Function(String value);  
  16.  
  17. //抽象事件,類型為系統(tǒng)預(yù)定義的代理(delegate):  
  18. EventHandler public abstract event EventHandler Event;  
  19.  
  20. //抽象索引指示器,只具有g(shù)et訪問器表示繼承類必須將該索引指示器實(shí)現(xiàn)為只讀  
  21. public abstract Char this[int Index] {   
  22. get;  
  23. }   
  24.  
  25. public class DeriveClass : BaseClass {   
  26. private String attribute;  
  27.  
  28. public override String Attribute {   
  29. get {   
  30. return attribute;  
  31. }   
  32. set {   
  33. attribute = value;  
  34. }   
  35. public override void Function(String value){   
  36. attribute = value;  
  37. if (Event != null){   
  38. Event(this, new EventArgs());  
  39. }   
  40. public override event EventHandler Event;  
  41. public override Char this[int Index] {   
  42. get {   
  43. return attribute[Index];  
  44. }   
  45.  
  46. class Program { static void OnFunction(object sender, EventArgs e){   
  47. for (int i = 0;   
  48. < ((DeriveClass)sender)。Attribute.Length;   
  49. i++){ Console.WriteLine(((DeriveClass)sender)[i]);  
  50. }   
  51. static void Main(string[] args){   
  52. DeriveClass tmpObj = new DeriveClass();  
  53. tmpObj.Attribute = "1234567";Console.WriteLine(tmpObj.Attribute);  
  54. //將靜態(tài)函數(shù)OnFunction與tmpObj對(duì)象的Event事件進(jìn)行關(guān)聯(lián)  
  55. tmpObj.Event += new EventHandler(OnFunction);  
  56. tmpObj.Function("7654321");  
  57. Console.ReadLine();  

C#基礎(chǔ)概念之internal 修飾符起什么作用?

internal 修飾符可以用于類型或成員,使用該修飾符聲明的類型或成員只能在同一程集內(nèi)訪問,接口的成員不能使用 internal 修飾符

示例:

 
 
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4.  
  5. namespace Example05Lib {   
  6. public class Class1 {   
  7. internal String strInternal = null;  
  8. public String strPublic;  

當(dāng)前文章:C#基礎(chǔ)概念學(xué)習(xí)筆記
瀏覽地址:http://www.dlmjj.cn/article/dpchspc.html