av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

C#初學(xué)——C#索引(index)

通過C#的一些學(xué)習(xí)內(nèi)容,我看到了C#索引的使用,感覺自己沒什么概念,就學(xué)習(xí)了下。感覺比較好,適合初學(xué)者。

為黃梅等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及黃梅網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為做網(wǎng)站、成都網(wǎng)站設(shè)計、黃梅網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!

下面是貼出來的代碼:

 
 
 
  1. using System;   
  2. using System.Collections.Generic;   
  3. using System.Linq;   
  4. using System.Text;   
  5.    
  6. namespace index   
  7. {   
  8.         class Worker   
  9.         {   
  10.                 public string LastName;   
  11.                 public string FirstName;   
  12.                 public string MyBirth;   
  13.    
  14.                 public string this[int index]   
  15.                 {   
  16.                         set   
  17.                         {   
  18.                                 switch (index)   
  19.                                 {   
  20.                                         case 0: LastName = value;   
  21.                                                 break;   
  22.                                         case 1: FirstName = value;   
  23.                                                 break;   
  24.                                         case 2: MyBirth = value;   
  25.                                                 break;   
  26.                                         default:   
  27.                                                 throw new ArgumentOutOfRangeException("index");   
  28.                                                 break;   
  29.                                 }   
  30.                         }   
  31.                         get   
  32.                         {   
  33.                                 switch(index)   
  34.                                 {   
  35.                                         case 0 : return LastName;   
  36.                                         case 1 : return FirstName;   
  37.                                         case 2 : return MyBirth;   
  38.                                         default :      
  39.                                                 throw new ArgumentOutOfRangeException("index");   
  40.                                                 break;   
  41.                                 }   
  42.                                            
  43.                         }   
  44.                 }   
  45.         }   
  46.         class Program   
  47.         {   
  48.                 static void Main(string[] args)   
  49.                 {   
  50.                         Worker a = new Worker();   
  51.                         Console.WriteLine("print the value:{0},{1},{2}",a[0],a[1],a[2]);   
  52.                         Console.WriteLine("please print your last name");   
  53.                         a[0] = Console.ReadLine();   
  54.                         Console.WriteLine("please print your first name");   
  55.                         a[1] = Console.ReadLine();   
  56.                         Console.WriteLine("please print your birthday");   
  57.                         a[2] = Console.ReadLine();   
  58.                         Console.WriteLine("Now,your name is {0},{1},and your birth is {2}",a[0],a[1],a[2]);   
  59.    
  60.                 }   
  61.         }   
  62. }  

首先什么是C#索引呢?

書上說它是一組get和set訪問器,我個人就直接這么認(rèn)為就是獲值或設(shè)值的概念。(可能是錯誤的啊,呵呵,理論太差,剛看的)。

怎樣聲明C#索引呢?

他的語法是如下:

要注意下面幾點:a:索引沒有名稱,它是通過關(guān)鍵字this。

                                   b:參數(shù)列表在方括號里面。

                                   c:參數(shù)列表至少必須聲明一個參數(shù)。

 
 
 
  1. ReturnType this [type param1,...]   
  2. {   
  3.         get   
  4.                 {   
  5.                         ...   
  6.                 }   
  7.         set   
  8.                 {   
  9.                         ...   
  10.                 }   
  11. }  

分享文章:C#初學(xué)——C#索引(index)
標(biāo)題網(wǎng)址:http://uogjgqi.cn/article/dhceeod.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流