Avatar of ITsolutionWizard
ITsolutionWizard
Flag 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

C#LINQ Query

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Miguel Oz

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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
Fernando Soto

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Fernando Soto

And what did the alert state?
kaufmed

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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
ITsolutionWizard

ASKER
can you show me how with my codes?
Fernando Soto

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

ITsolutionWizard

ASKER
List strong
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Fernando Soto

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