c# - Implicit Type Inference only for lambda expressions ? Why ? Confused ! -


I have the following sample code (C # 3.5 for study purposes only!).

I am making a call to the Sort function which accepts an IEnumerable and sort function. If I call it using Lambda Expression (Case A), then the compiler can retrieve the return type trashleਟ, but when I pass through the funcent (case B), the compiler throws an error!

I am unable to understand why the compiler can not bring a tracheal in another case! I think that really going to the same information or is it not right?

Please help!

  int [] intArray = {1, 3, 2, 5, 1}; IEnumerable & LT; Integer & gt; IntArray2 = Sort (intere, x = & sortInt (x)); // & lt; = Case A - OK! IEnumerable & LT; Integer & gt; NextIntArray = sort (intere, sorted); // & lt; = Case B - Compilation Error: Can not Type! Public stable IEnumerable & lt; TResult & gt; Sort & lt; T, TResult & gt; (IEnumerable & lt; T & gt; toBeSorted, Func & lt; IEnumerable & lt; T & gt ;, IEnumerable & lt; trust & gt; & gt; sortFunc} {return sortFunc (toBeSorted); } Public stable IEnumerable & lt; Int & gt; SortInt (IEnumerable & lt; int & gt; array) {return array. Order birthing (x = & gt; x); } It appears that the estimation fails on your second example because the compiler can not perform. Overload resolution on  

This can be useful as a more intense explanation:


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -