Lambda Expression- Compare list with custom collection

Following example illustrates how to compare the string list with custom collection using Lambda expression

class Program
{
public class First
{
      public string Name
     {
             get;
              set;
   }
}

static void Main(string[] args)
{
List nameList = new List {“Hai”, “Welcome”};
First first = new First
{
Name = “Hai”
};
List firstList = new List
{
first
};

bool result = (firstList.Any(field => nameList.Contains(field.Name)));
if(result)
{
Console.WriteLine(“Name Found in name list…”);
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: