title: How to return a List type variable containing values from LINQ query result in C#.Net?
body: <p>Im trying to return a query result containing information from the user logged in storing it inside a list datatype but my return variable is underlined red, so i could display the data on the html page but it's giving an error on the line, <em>return UserInfo;</em> saying:</p>
  
  <blockquote>
    <p>Error 2   Cannot implicitly convert type 'Project.Models.User' to
    'System.Collections.Generic.List'</p>
  </blockquote>
  
  <p>I dont know if my query works either but Im only trying to return the first row of the result only. Here is my code:</p>
  
  <pre><code>public List&lt;Models.User&gt; GetUserInfo(Func&lt;String&gt; username)
  {
      List&lt;Models.User&gt; UserInfo;
  
      if (username != null)
      {
          try{
              var User =  from m in db.MstUsers
                          where m.UserName == Convert.ToString(username)
                          select new Models.User
                          {
                              UserName = m.UserName,
                              FirstName = m.FirstName,
                              LastName = m.LastName,
                              EmailAddress = m.EmailAddress,
                              PhoneNumber = m.PhoneNumber
  
                          };
  
              if (User.Any())
              {
                  var Info = new List&lt;Models.User&gt; { User.First() };
                  UserInfo = Info.ToList();
              }
          }
          catch
          {
              UserInfo = new List&lt;Models.User&gt;();
          }
  
      }
      return UserInfo;
  }
  </code></pre>
  
  <p>(Edit) I also created a function to read the cookie, here is my code:</p>
  
  <pre><code> public String GetCookie()
          {
              string username = "";
              var cookie = Request.Headers.GetCookies("MyCookie").SingleOrDefault();
  
              if (cookie != null)
              {
                  username = cookie["MyCookie"].Value;
              }
  
              return username;
          }
  </code></pre>
  
  <p>How do I determine what type of variable I want to return? Is it not right to use List as the datatype function so that I could return a List variable? Im really having trouble understanding the concepts of returning the values in C#. Im still new in C# .Net and I dont know how to solve this problem at all. Im using Visual Studio 2013. Can anyone help me, please?</p>