Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net c#延拓法_Asp.net_Asp.net Mvc 2_Oop_Extension Methods - Fatal编程技术网

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>();