return value error

Hello,

here is my code

 public static List<Info> List(List<Info> list)
        {       
            list.Add(new Info() { UID = _UID });

            List<Info> SortedList = list.OrderBy(o => o._UID).ToList();

            var firstItem = SortedList.ElementAt(0);

            return firstItem;
        }

Open in new window


Error i get is
Cannot implicitly convert type Info into 'System.Collections.Generic.List<Info>'.

Can someone help with me solution?
TagyourareitAsked:
Who is Participating?
 
Jeffrey Dake Senior Director of TechnologyCommented:
I am assuming you want to return the first item. Which means you should be returning the type that is in the list not the list itself

public static Info list(List<Info> list)

Open in new window


The return type you specify in your method signature must match the type you return in the function.
0
 
Mark BullockQA Engineer IIICommented:
Replace your last two statements with this:
return SortedList;

Open in new window

0
 
Fernando SotoRetiredCommented:
Hi Tagyourareit;

This is the signature of the function List from your code. Please note that the signature states that the return value is to be a List<info> that is a collection of info objects but what you are returning is a single instance of info.
 
 
public static List<Info> List(List<Info> list)

Open in new window

You are returning this :
var firstItem = SortedList.ElementAt(0);

return firstItem;

Open in new window

Which is the first element of the collection.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.