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

C#foreach使用實(shí)例淺析

C# foreach使用實(shí)例向你全面展示了C# foreach的使用規(guī)范,以及在C# foreach中特別要注意的關(guān)鍵是實(shí)現(xiàn)IEnumerable 和IEnumerator 這兩個(gè)接口:那么學(xué)習(xí)C# foreach這一C#新加入的語(yǔ)句,我們還是要多多練習(xí)和體會(huì)。

專注于為中小企業(yè)提供成都網(wǎng)站制作、做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)南安免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了超過(guò)千家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

C# foreach使用1. MySplit 類

 
 
 
  1. ///   
  2.  /// MySplit 類  
  3.  ///   
  4.  public class MySplit : IEnumerable  
  5.  {  
  6. private string[] elements;  
  7.  
  8. public MySplit(string source, char[] delimiters)  
  9. {  
  10. elements = source.Split(delimiters);  
  11. }  
  12.  
  13. IEnumerator IEnumerable.GetEnumerator()  
  14. {  
  15. return new MyEnumerator(this);  
  16. }  
  17.  
  18. #region 在嵌套類中實(shí)現(xiàn) IEnumerator 接口  
  19. ///   
  20. /// 在嵌套類中實(shí)現(xiàn) IEnumerator 接口,以便以后方便創(chuàng)建多個(gè)枚舉  
  21. ///   
  22. public class MyEnumerator : IEnumerator  
  23. {  
  24. private int position = -1;  
  25. private MySplit t;  
  26.  
  27. public MyEnumerator(MySplit t)  
  28. {  
  29.  this.t = t;  
  30. }  
  31.  
  32. public bool MoveNext()  
  33. {  
  34.  if (position < t.elements.Length - 1)  
  35.  {  
  36. position++;  
  37. return true;  
  38.  }  
  39.  else 
  40.  {  
  41. return false;  
  42.  }  
  43. }  
  44.  
  45. public void Reset()  
  46. {  
  47.  position = -1;  
  48. }  
  49.  
  50. object IEnumerator.Current  
  51. {  
  52.  get 
  53.  {  
  54. try 
  55. {  
  56. return t.elements[position];  
  57. }  
  58. catch (IndexOutOfRangeException)  
  59. {  
  60. throw new InvalidOperationException();  
  61. }  
  62.  }  
  63. }  
  64. }  
  65. #endregion  
  66.  }  

C# foreach使用2. 使用過(guò)程(注意規(guī)范)

 
 
 
  1. MySplit mySplit = new MySplit("大豆男生: I Love You!", new char[] { ' ', '-' });  
  2.  foreach (string item in mySplit)  
  3.  {  
  4. Console.WriteLine(item);  
  5.  } 

C# foreach使用3. 程序輸出結(jié)果

 
 
 
  1. 大豆男生:  
  2. I  
  3. Love  
  4. You! 

C# foreach使用的情況就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)以及C# foreach使用有所幫助。


文章名稱:C#foreach使用實(shí)例淺析
本文路徑:http://uogjgqi.cn/article/cdsiepi.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

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