1
以下代碼在泛型T上產生錯誤,我不明白爲什麼。任何人都可以解釋我做錯了什麼,以及正確的做法是什麼?使用IEnumerable <T>作爲方法的輸入
代碼:
public static class CSVWriter
{
public static void WriteData(string fileName, string path, IEnumerable<T> data)
{
string filePath = path + fileName + ".csv";
if (!File.Exists(filePath))
{
File.Create(filePath).Close();
}
StringBuilder sb = new StringBuilder();
foreach (var item in data)
{
sb.AppendLine(data.ToString());
}
File.AppendAllText(filePath, sb.ToString());
}
}
錯誤:
Error CS0246
The type or namespace name 'T' could not be found
(are you missing a using directive or an assembly reference?)