I want to pass an array of custom objects to a function like String.Join
which has the following signatures:
public static string Join(string separator, params Object[] values)
public static string Join(string separator, IEnumerable<T> values)
If I call the function like this:
var arr = new MyClass[]{ new MyClass(), new MyClass() };
string text = string.Join("
", arr);
I get a compiler error:
The call is ambiguous between the following methods or properties: 'string.Join(string, params object[])' and 'string.Join(string, System.Collections.Generic.IEnumerable)'
I can resolve the ambiguity by using the IEnumerable<T>
function:
var arr = new MyClass[]{ new MyClass(), new MyClass() };
string text = string.Join<MyClass>("
", arr);
But can I call the params object[]
function?
I am using C# 4.0, if that makes any difference.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…