c# - Why does Select(x => ...Cast<x.GetType()>()) not work? -


why following code produce error?

var listoflist = new list<list<string>>(); var tmp = listoflist.select(x => x.orderby(y => y).cast<x.gettype()>()); 

error:

operator '<' cannot applied operands of type 'method group' , 'system.type'

the code looks silly, because it's extremly simplified real example. wonder why not work exactly. works if replace x.gettype() list<string>, don't type of x @ runtime.
clarification: don't necessary solution. want know wrong code.

the correct way write code use tolist instead of cast mentioned elsewhere.

however answer question "what wrong code?" there 2 specific points start with:

  • using cast<x.gettype()>():

generics used compile time type variables, putting cast<list<string>>() make more sense here - x.gettype() resolved @ run time. guess message you're getting result of compiler getting muddled on point.

  • attempting cast list<string>:

even if specific cast code syntax reasonable, actual cast still fail. @ point you're attempting cast orderedenumerable<string> list<string>. isn't valid cast. tolist() resolves otherwise un-resolved orderby statement list.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -