日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#this關(guān)鍵字介紹

C# this關(guān)鍵字引用類的當(dāng)前實(shí)例。

成都創(chuàng)新互聯(lián)公司自2013年創(chuàng)立以來,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站制作、網(wǎng)站建設(shè)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元鄱陽做網(wǎng)站,已為上家服務(wù),為鄱陽各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:18980820575

以下是 this 的常用用途:
◆限定被相似的名稱隱藏的成員
◆將對(duì)象作為參數(shù)傳遞到其他方法
◆聲明索引器

C# this關(guān)鍵字示例:

 
 
 
  1. //this關(guān)鍵字  
  2. //keywords_this.cs  
  3. usingSystem;  
  4. classEmployee  
  5. {  
  6. privatestring_name;  
  7. privateint_age;  
  8. privatestring[]_arr=newstring[5];  
  9.  
  10. publicEmployee(stringname,intage)  
  11. {  
  12. //使用this限定字段,name與age  
  13. this._name=name;  
  14. this._age=age;  
  15. }  
  16.  
  17. publicstringName  
  18. {  
  19. get{returnthis._name;}  
  20. }  
  21.  
  22. publicintAge  
  23. {  
  24. get{returnthis._age;}  
  25. }  
  26.  
  27. //打印雇員資料  
  28. publicvoidPrintEmployee()  
  29. {  
  30. //將Employee對(duì)象作為參數(shù)傳遞到DoPrint方法  
  31. Print.DoPrint(this);  
  32. }  
  33.  
  34. //聲明索引器  
  35. publicstringthis[intparam]  
  36. {  
  37. get{return_arr[param];}  
  38. set{_arr[param]=value;}  
  39. }  
  40.  
  41. }  
  42. classPrint  
  43. {  
  44. publicstaticvoidDoPrint(Employeee)  
  45. {  
  46. Console.WriteLine("Name:{0}\nAge:{1}",e.Name,e.Age);  
  47. }  
  48. }  
  49.  
  50. classTestApp  
  51. {  
  52. staticvoidMain()  
  53. {  
  54. EmployeeE=newEmployee("Hunts",21);  
  55. E[0]="Scott";  
  56. E[1]="Leigh";  
  57. E[4]="Kiwis";  
  58. E.PrintEmployee();  
  59.  
  60. for(inti=0;i<5;i++)  
  61. {  
  62. Console.WriteLine("FriendsName:{0}",E[i]);  
  63. }  
  64.  
  65. Console.ReadLine();  
  66. }  
  67. }  
  68.  
  69. /**//*  
  70. 控制臺(tái)輸出:  
  71. Name:Hunts  
  72. Age:21  
  73. FriendsName:Scott  
  74. FriendsName:Leigh  
  75. FriendsName:  
  76. FriendsName:  
  77. FriendsName:Kiwis  
  78. */ 

由于靜態(tài)成員函數(shù)存在于類一級(jí),并且不是對(duì)象的一部分,因此沒有this指針。在靜態(tài)方法中引用C# this關(guān)鍵字是錯(cuò)誤的。索引器允許類或結(jié)構(gòu)的實(shí)例按照與數(shù)組相同的方式進(jìn)行索引。索引器類似于屬性,不同之處在于它們的訪問器采用參數(shù)。


網(wǎng)頁名稱:C#this關(guān)鍵字介紹
分享地址:http://m.5511xx.com/article/dhjhhgj.html