Very simple extension method not compiling:
public static string Join(this string text, params string[] stringsToJoin)
{
return String.Join(", ", stringsToJoin.Where(s => !string.IsNullOrEmpty(s)));
}
I get "cannot convert from 'System.Collections.Generic.IEnumerable' to 'string[]'"
What am I missing?
The overload of String.Join
which accepts an IEnumerable<String>
was only added in .NET 4.0. It seems you're compiling against an earlier version.
The easiest way to fix this and make it compatible with .NET 3.5 would be to simply call .ToArray()
:
public static string Join(this string text, params string[] stringsToJoin)
{
return String.Join(", ", stringsToJoin.Where(s => !string.IsNullOrEmpty(s))
.ToArray());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With