I have written and used some class extensions succesfully. However, although I can write the following one, I can’t figure out how to call it. This particular one is intended to convert an attribute style key-value pair list to a string.
public static class Extensions
{
public static string AttributesToString<T, T1>(this Dictionary<T, T1> dict)
{
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<T, T1> kv in dict)
{
sb.Append(" " + kv.Key + "=\"" + kv.Value + "\"");
}
return sb.ToString();
}
}
The following doesn’t work:
Dictionary<string, string> dict = new Dictionary<string, string>();
dict.AttributesToString() // error
How can I call this extension?
You’ve got some kind of build or scope error. This works perfectly. Are your extension methods in another assembly or namespace?