C# - Why can't I cast from a List<MyClass> to List<object>?

C# - Why can't I cast from a List<MyClass> to List<object>?

C#

I have a List of objects, which are of my type QuoteHeader and I want to pass this list as a list of objects to a method which is able to accept a List<object>.

My line of code reads...

Tools.MyMethod((List<object>)MyListOfQuoteHeaders);

But I get the following error at design time...

Cannot convert type 'System.Collections.Generic.List<MyNameSpace.QuoteHeader>' 
to 'System.Collections.Generic.List<object>'

Do I need to do anything to my class to allow this? I thought that all classes inherit from object so I can't understand why this wouldn't work?

IEnumerable myNewEnumerable = myEnumerable.Cast();

Source:

Why can't I cast from a List to List? - https://stackoverflow.com/a/5881725/1694775

Previous Post Next Post