c# - why microsoft allowed list<object> = new list<object>() feature from 2.0? -


i have been learning collection , generics , understood generics introduced provide more type safe containers , improve application performance reducing number of boxing/unboxing.

but, if case, why framework allows create generics collection of type system.objects can take other type?

list<object> listobj = new list<object>();  listobj.add(new program1()); listobj.add(new program2()); 

thanks in advance.

if want list of things neither same type, nor share base class, nor share interface, need list<object>.

you need this.

but if pursue thought list<object> should disallowed because encourages unnecessary , dangerous downcasts, , anyway generics can specify types can handle, shouldn't go way , disallow use of object entirely?


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -