Click here to Skip to main content
15,878,231 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Class Structure:
public List<customer> CustomerDetails { get; set; }
public class customer
public string Key { get; set; }
public int? FirstAmount{ get; set; }
public int? SecondAmount{ get; set; }
public int? Total{ get; set; }
Response Data:
"Details": {
"Status": "0",
"customer": [
"FirstAmount": "796.61",
"SecondAmount": "392.43",
"total": "2",
"key": "Platinum"
"FirstAmount": "0.00",
"SecondAmount": "0.00",
"total": "0",
"key": "Gold"

Required: *How to select the customer data with Key value "Gold" from the response data. Example need SecondAmount of Customer with Key value "Gold"

What I have tried:

customer.Gold.SecondAmount = CustomerDetails.customer.Select(x => x.SecondAmount).Where(x => x.key.ToString() == ">Gold");
Updated 18-Aug-22 21:27pm

1 solution

Remove the ">" character to start with:
customer.Gold.SecondAmount = CustomerDetails ... == ">Gold");
Then change "key" to "Key" to match your class definition - C# is case sensitive, so they are not the same field name!.
You can also remove the ToString call since the Key field is already a string.

Then think about what the Where call will return.
Is it a single item? Or a collection of items?

And since the customer class doesn't have any static members, you would need an instance of the class to assign to, and a Gold field or property to work with!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900