Is there some way to get a java List<?>
in C#?
I need to get a IEnumerable<T>
, where T
can be either a class
(string), or a struct
(int, double...).
public interface I
{
IEnumerable<object> Enumers { get; }
}
public class A<T> : I
{
IEnumerable<T> ts;
public IEnumerable<object> Enumers
{
get { return (IEnumerable<object>)this.ts; }
}
}
public class Test
{
public static void Main()
{
A<double> a = new A<double>();
var x = a.Enumers; //It crashes here.
}
}
It crashes at runtime, since it's not possible to cast from IEnumerable<T>
to IEnumerable<object>
.
Any ideas?