I'm trying to write a library with .NetStandard 2.0, and apparently there's not an overload for the string.Join
method that accepts an IEnumerable. This code works fine in .NetCore 2.0, but not standard:
string.Join('/', parts.Skip(index))
The overload exists with a string separator
instead of just char separator
:
string s = string.Join("/", parts.Skip(index));
so... use that?
To add a bit of context to the answer by Marc Gravell: .NET Standard and .NET Core have a different set of APIs.
.NET Standard represents a set of APIs that need to be implemented by a platform if it supports a version of .NET Standard.
.NET Core is a platform that implements .NET Standard. In addition to those APIs, it implements a few more.
The APIs available on .NET Standard for string.Join
are (from https://github.com/dotnet/standard/blob/master/netstandard/ref/mscorlib.cs):
public static System.String Join(System.String separator, System.Collections.Generic.IEnumerable<string> values) { throw null; }
public static System.String Join(System.String separator, params object[] values) { throw null; }
public static System.String Join(System.String separator, params string[] value) { throw null; }
public static System.String Join(System.String separator, string[] value, int startIndex, int count) { throw null; }
public static System.String Join<T>(System.String separator, System.Collections.Generic.IEnumerable<T> values) { throw null; }
For .NET Core, the set of APIs is bigger since APIs were added to the .NET Core platform but not to .NET Standard (from https://github.com/dotnet/corefx/blob/master/src/System.Runtime/ref/System.Runtime.cs#L2307):
public static System.String Join(char separator, params object[] values) { throw null; }
public static System.String Join(char separator, params string[] value) { throw null; }
public static System.String Join(char separator, string[] value, int startIndex, int count) { throw null; }
public static System.String Join(System.String separator, System.Collections.Generic.IEnumerable<string> values) { throw null; }
public static System.String Join(System.String separator, params object[] values) { throw null; }
public static System.String Join(System.String separator, params string[] value) { throw null; }
public static System.String Join(System.String separator, string[] value, int startIndex, int count) { throw null; }
public static System.String Join<T>(char separator, System.Collections.Generic.IEnumerable<T> values) { throw null; }
public static System.String Join<T>(System.String separator, System.Collections.Generic.IEnumerable<T> values) { throw null; }
If you are targeting .NET Core, you can use the overload that takes a char
.
If you are targeting .NET Standard, you can use the overload that takes a string
.
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