21 Replies
Wha
You mean a list that can have any type of object?
a
List<T>
can only have T
in it. Thats the entire purpose of generics.If you really want to have a workaround you’d have to make T an
I did not format that well
Downside of that is you'd need runtime type checking to actually do anything useful with the item
List<Any object>
List<object>
but as said above, that removes any and all benefits of using genericsArrayList
iirc
List<object>
is actually prefered over ArrayList
:dyes
Indeed it is, also this is outside the scope of this post but how does the ArrayList.Sort function even work
Like it can have different type of objects what’s it sorting based on
Who knows 🙂
new List<object>() { "something" };
no worky
:(With collection initializers you have to omit the ()
no you don't
Thinker
REPL Result: Success
Result: List<object>
Compile: 386.597ms | Execution: 72.199ms | React with ❌ to remove this embed.
I'd like to know why you need a list with several different types in it, @Livid
i don
Genuinely surprising
Reading the docs it was always omitted so I assumed it was a necessity
?
Whyd you ask then
comboBox1.DataSource = new List<object>() { "something" };
Error Code: CS0246 -> Description: The type or namespace name 'List<>' could not be found (are you missing a using
System.Collections.Generic
Add a using statement for that namespace
yay