-3
//如何創建一個方法,使下面的代碼將工作如何創建一個方法,使下面的代碼將工作
const string abc = "asduqwezxc";
foreach (var vowel in abc.SelectOnlyVowels())
{
Console.WriteLine("{0}", vowel);
}
//如何創建一個方法,使下面的代碼將工作如何創建一個方法,使下面的代碼將工作
const string abc = "asduqwezxc";
foreach (var vowel in abc.SelectOnlyVowels())
{
Console.WriteLine("{0}", vowel);
}
你需要寫an extension method,就像這樣:
public static class StringExt
{
public static IEnumerable<char> SelectOnlyVowels(this string self)
{
return self.Where(c => "aeiou".Contains(char.ToLower(c)));
}
}
在const的代碼開始 – BTJ
突出的代碼,然後點擊右鍵並選擇狀態選項'Refactor->提取Method' – MethodMan
我敢肯定,他問該怎麼寫'SelectOnlyVowels'串擴展 – Jonesopolis