Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.Join doesn't accept IEnumerable<string>

Tags:

c#

.net-3.5

I have a method with this signature:

IEnumerable<string> GetCombinations(string s, int length)

And I am trying to use it with string.Join like this:

var combinations = GetCombinations(text, 2);
string result = string.Join(", ", combinations);

But I get the following compiler error:

cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string[]'

Can't string.Join take an IEnumerable<string>?


1 Answers

What version of the .NET Framework are you using? The overload of String.Join that accepts an IEnumerable instead of an array was added in .NET 4.

like image 139
Dan J Avatar answered Jul 30 '26 10:07

Dan J



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!