Sosi
Sosi

Reputation: 2578

c# Extension method

Im trying to test my extension method that converts a list of strings in a string comma separated:

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
      }
}

The issue is that in the method TestExtension i cant use ToCommaString method.

Do you know what's happening?

Could i make available for all my web application this extension method registering in web.config or something similar?

Thanks in advance.

Best regards.

Jose

Upvotes: 0

Views: 245

Answers (1)

cjk
cjk

Reputation: 46475

You're declaring your list to be the wrong type (non-generic):

IList test=new List<string>(); 

It should be

IList<String> test=new List<string>(); 

Upvotes: 7

Related Questions