Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a list of class
C#
      public class PrintUTAccural
      {
          public string PropertyName { get; set; }
          public string VendorName { get; set; }
          public string VendorNumber { get; set; }
          public string InvoiceNumber { get; set; }
          public DateTime? InvoicePostDate { get; set; }
          public string UseTaxName { get; set; }
          public decimal UseTaxExemptAmount { get; set; }
          public decimal UseTaxAmount { get; set; }
          public decimal UseTaxNonExemptAmount { get; set; }
          public decimal InvoiceAmount { get; set; }           
      }
string Name= "Nath"

and i have to find a name "Nath" from this list through lambda expression then how i get it.
C#
string VenderNumber = UtAccuralLstForComp.Where(x => x.VendorName == Name).Select(x => x.VendorNumber).SingleOrDefault();


i am using this but didn't get value

[Edit]Code block added[/Edit]
Posted
Updated 14-Jan-18 14:55pm
v2
Comments
David_Wimbley 22-May-13 14:27pm    
Can you show how you are populating the list.

List<PrintUTAccural> list = new List<PrintUTAccural>();
list.Add(new PrintUTAccural{ VendorName = "David", VendorNumber = "1"});
list.Add(new PrintUTAccural{ VendorName = "Nath", VendorNumber = "88"});
list.Add(new PrintUTAccural{ VendorName = "Thom", VendorNumber = "3"});
list.Add(new PrintUTAccural{ VendorName = "Wilson", VendorNumber = "4"});

string VenderNumber = list.Where(x => x.VendorName == "Nath").Select(x => x.VendorNumber).SingleOrDefault();

Console.WriteLine("Vendor Number: " + VenderNumber);

I did the above and your code worked fine.
Pheonyx 22-May-13 15:10pm    
It might be worth trying FirstOrDefault() instead of SingleOrDefault()?

have a read here:
http://social.msdn.microsoft.com/Forums/en-US/oslo/thread/7ab62c94-0da3-4d6a-92aa-070d9ff8441f

1 solution

string VenderNumber = UtAccuralLstForComp.Where(x => x.VendorName == Name).SingleOrDefault().VendorName
 
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