Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have list
C#
<pre>public class CompanyDetails
        {
            public long id { get; set; }
            public string companyName { get; set; }
           
        }

List<companydetails> cp = new List<companydetails>();
cp.add("Compudyne Winfosystems Limited");
cp.add("Infosys");

string cpName=CompanyName.Where(p => p.CompanyName.Contains("inf")).Tolist();

is returning only "Compudyne Winfosystems Limited" not returning
Infosys


it should return both the value b/c it contains "inf" in both the company name

What I have tried:

i have tried all the ways to figure it out
Posted
Updated 17-Dec-20 23:53pm
Comments
BillWoodruff 18-Dec-20 8:24am    
It is obvious from this code that will never compile that have not tried anything,

1 solution

It's case-sensitive so "Infosys" doesn't contain "inf", but it does contain "Inf". Try something like

C#
List<CompanyDetails> cp = new List<CompanyDetails>();
cp.Add(new CompanyDetails { companyName = "Compudyne Winfosystems Limited" });
cp.Add(new CompanyDetails { companyName = "Infosys" });

List<CompanyDetails> cpName = cp.Where(p => p.companyName.IndexOf("inf", StringComparison.CurrentCultureIgnoreCase) != -1).ToList();
 
Share this answer
 
v4
Comments
BillWoodruff 18-Dec-20 8:26am    
It's obvious from the OP's code that he never tried anything.

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