我有以下我在.NET 4.0項目類型或命名空間名稱「T」找不到
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
}
}
public static class Utility
{
public static IEnumerable<T> Filter1(this IEnumerable<T> input, Func<T, bool> predicate)
{
foreach (var item in input)
{
if (predicate(item))
{
yield return item;
}
}
}
}
}
正在編譯代碼,但得到以下錯誤。 System.dll已經包含在引用中作爲默認值。我可能做錯了什麼?
Error 1 The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)
Error 2 The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)
Error 3 The type or namespace name 'T' could not be found (are you missing a using directive or an assembly reference?)
+1,我假定你不能做一個靜態類通用。 –
@PaulPhillips - 我其實只是試過了,我不認爲你可以。我刪除了這部分答案。 – SwDevMan81
我在linqpad上工作,雖然調用很笨拙。你必須做'Utility .Filter()' –