2016-11-12 40 views
0

我想用StartsWith以用戶給出的字母打印名稱。但是我不知道如何在Visual Studio中使用StartsWith。 Visual Studio無法識別它。如何在Visual Studio中使用Startswith

 ArrayList namen = new ArrayList(); 
     int kosten = 0; 
     string naam; 
     Console.Write("voer de namen in: "); 
     naam = Console.ReadLine(); 


     while (naam.Length > 0) 
     { 
      if (namen.Contains(naam) == false) 
      { 
       namen.Add(naam); 
      } 

      Console.Write("Voer de namen in: "); 
      naam = Console.ReadLine().ToLower(); 
     } 

     foreach (string n in namen) 
     { 
      Console.WriteLine(n); 
      kosten += 10; 
     } 

     Console.WriteLine(kosten + " euro"); 
     Console.WriteLine("voer een letter in: "); 
     string letter = Console.ReadLine(); 

這是我想要使用方法StartsWith的代碼。

+0

檢查的例子[本站](https://www.dotnetperls.com/startswith) – Odrai

回答

0

如果你想檢查namen ArrayList的StartsWith一個字母的名稱,可以使用下面的例子:

 string letter = Console.ReadLine(); 
     ArrayList namen = new ArrayList(); 
     foreach (string name in namen) 
     { 
      if(name.StartsWith(letter)) 
      { 
       // Yes, the name StartsWith the input letter 
       // Do Something 
      } 
     } 
+0

它給了我這個錯誤:嚴重\t代碼\t說明\t項目\t文件\t行\t抑制狀態 錯誤\t CS1061 \t'ArrayList'不包含'Startswith'的定義,也沒有擴展方法'Startswith'接受'ArrayList'類型的第一個參數被發現(你是否缺少使用指令或程序集引用?)\t bijles_taak_werken遇到數組\t C:\ Users \ e6430S \ Documents \ Visual Studio 2015 \ Projects \ bijles_taak_werken遇到陣列\ bijles_taak_werken遇到陣列\ Program.cs 活動 –

+0

不要感謝你 –