We help IT Professionals succeed at work.

c# var, linq

ITsolutionWizard
on
197 Views
Last Modified: 2019-01-28
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

Comment
Watch Question

Senior Software Engineer
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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);
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
And what did the alert state?
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
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.

Author

Commented:
can you show me how with my codes?
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
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

Author

Commented:
List strong
Fernando SotoRetired
CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
List<XXX>, list of what, what object type is XXX? Please also post the class XXX.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.