I am porting some Java code to C# and I ran across this:
List<?>
As I understand it this is a List of type Unknown. As a result I can dictate the type elsewhere (at runtime? I’m not sure).
What is the fundamental equivalent in C#?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think the best match to Java’s
List<?>would be C# 4.0IEnumerable<out T>If you have a method that takesList<?>than you can call it withList<Object>andList<String>like so:C# 4.0
IEnumerable<T>interface is actuallyIEnumerable<out T>, which means that if, say,Rderives fromT,IEnumerable<T>can be assigned to fromIEnumerable<R>.So, all you have to do is make your
doSomethingintoDoSomethingand have acceptIEnumerable<T>parameter:EDIT: If C# 4.0 is not available, you can always fall back to either untyped
IEnumerableorIList.