Asp.net c#延拓法
我正在尝试测试我的扩展方法,该方法将字符串列表转换为逗号分隔的字符串:Asp.net c#延拓法,asp.net,asp.net-mvc-2,oop,extension-methods,Asp.net,Asp.net Mvc 2,Oop,Extension Methods,我正在尝试测试我的扩展方法,该方法将字符串列表转换为逗号分隔的字符串: public static class Extensions { public static string ToCommaString<T>(this IList<T> input) { StringBuilder sb = new StringBuilder(); foreach (T value in input) {
public static class Extensions
{
public static string ToCommaString<T>(this IList<T> input)
{
StringBuilder sb = new StringBuilder();
foreach (T value in input)
{
sb.Append(value);
sb.Append(",");
}
return sb.ToString();
}
public void TestExtension()
{
IList test=new List<string>();
//test.ToCommaString doesnt appear
}
}
公共静态类扩展
{
公共静态字符串ToCommaString(此IList输入)
{
StringBuilder sb=新的StringBuilder();
foreach(输入中的T值)
{
附加(价值);
某人加上(“,”);
}
使某人返回字符串();
}
public void TestExtension()
{
IList测试=新列表();
//test.ToCommasting未出现
}
}
问题是在TestExtension方法中,我不能使用ToCommasting方法
你知道发生了什么事吗
我可以为我的所有web应用程序提供在web.config或类似文件中注册此扩展方法吗
提前谢谢
致以最良好的祝愿
Jose您将列表声明为错误类型(非通用):
IList测试=新列表();
应该是
IList<String> test=new List<string>();
IList测试=新列表();
IList<String> test=new List<string>();