Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

c# var, linq

The codes below is working ok. I just need to make VAR response to be sorted.
How can I do that?

   public static List<Make> GetVehicleMakeList()
        {
            List<Make> lstMake = new List<Make>();
            HttpClient objClient = new HttpClient();
            try
            {
                var response = objClient.GetStringAsync(Utility.Enumeration.vehicleMakeAPICall).Result;
                if (!string.IsNullOrEmpty(response))
                {
                    VehicleMakeAPIResponse objMakeResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<VehicleMakeAPIResponse>(response);
                    return objMakeResponse.Results;
                }

            }
            catch (Exception ex)
            {

                //log error message here
            }
            return lstMake;
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ITsolutionWizard

ASKER

can you help me with using my codes?

I tried below and got alert. by the way, i would like to do sort (make_name) asc.

 return objMakeResponse.Results.OrderByDescending(s => s.Make_Name);
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And what did the alert state?
Your method returns a List<Make>, but OrderByDescending returns an IOrderedEnumerable. You'll want to either call ToList after OrderByDescending or change your method signature.
can you show me how with my codes?
In order to help you please tell us what is the data type being returned by the following statement?
var response = objClient.GetStringAsync(Utility.Enumeration.vehicleMakeAPICall).Result

Open in new window

List strong
List<XXX>, list of what, what object type is XXX? Please also post the class XXX.