cherry
cherry

Reputation: 37

c# Search Result From Contains String Class Contains List For Find String

    public class WorkingList
    {
        public string Name { get; set; }

        public bool Working { get; set; }
    }

Class WorkingList is Contains String

i want use like

       public List<WorkingList> Work = new List<WorkingList>(); 
       bool ContainsCheck=false;
       foreach(WorkingList list in Work)
       {
          if(list.Name.Equals("FindName")) { ContainsCheck = true; break }
       }

I Want Know Easy get List contains String Method!

using linq ? or anymethod / and

          public class TopClass
          {
             public List<WorkingList> Work = new List<WorkingList>(); 
             public string TopName { get; set; }
          }

i want know easy way Topclass.Work.Name contains string result

Upvotes: 1

Views: 85

Answers (2)

Oleksandr
Oleksandr

Reputation: 5678

bool ContainsCheck = Work.Any(list => list.Name.Equals("FindName"));

Upvotes: 2

Zebra
Zebra

Reputation: 66

You can use this:

  ContainsCheck =work.any(i=>i.Name=="FindName");

Upvotes: 0

Related Questions