Here's how:
String s = String.Join(", ", (from extension in extensions select extension.ToUpper()).ToArray());
Note, I probably would not write this as a single line, rather like this:
String s = String.Join(", ",
(from extension in extensions
select extension.ToUpper()).ToArray());
If you don't mind just using the Linq extension methods directly, instead of the Linq query syntax, you can use this:
String s = String.Join(", ", extensions.Select(e => e.ToUpper()).ToArray());
Another option would be to simply call ToUpperin the final line:
String s = String.Join(", ", extensions.ToArray()).ToUpper();
Finally, in .NET 4.0 String.Join, it finally supports IEnumerable<String>directly, so this is possible:
String s = String.Join(", ", extensions).ToUpper();
, . , , "filename.txt", "filename.txt", .
ToUpper Distinct, .
Linq + code :
String[] distinctExtensions = files
.Select(fileName => Path.GetExtension(fileName).ToUpper())
.Distinct()
.ToArray();
String distinctExtensionsAsString = String.Join(", ", distinctExtensions);
, :
public static class StringExtensions
{
public static String Join(this IEnumerable<String> elements, String separator)
{
if (elements is String[])
return String.Join(separator, (String[])elements);
else
return String.Join(separator, elements.ToArray());
}
}
:
String distinctExtensionsAsString = files
.Select(fileName => Path.GetExtension(fileName).ToUpper())
.Distinct()
.Join(", ");