LINQ Contains

If you have 2 collections and you need to figure out what values are in one collection and not in the other, you can do this:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            List<SomeType> _List1 = new List<SomeType>();
            List<SomeType> _List2 = new List<SomeType>();

            _List1.Add(new SomeType { Id = 1, Name = "Test1", Value = "Value1" });
            _List1.Add(new SomeType { Id = 2, Name = "Test2", Value = "Value2" });
            _List1.Add(new SomeType { Id = 3, Name = "Test3", Value = "Value3" });
            _List1.Add(new SomeType { Id = 4, Name = "Test4", Value = "Value4" });

            _List2.Add(new SomeType { Id = 1, Name = "Test1", Value = "Value1" });
            _List2.Add(new SomeType { Id = 2, Name = "Test2", Value = "Value2" });
            _List2.Add(new SomeType { Id = 3, Name = "Test3", Value = "Value3" });
            

            List<SomeType> _NotInList2 = (from l1 in _List1
                                          where !(from l2 in _List2 select l2.Name).Contains(l1.Name)
                                          select l1).ToList();

            foreach (SomeType _Value in _NotInList2)
            {
                Console.WriteLine(_Value.Name);
            }
        }
    }

    class SomeType
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Value { get; set; }
    }
}

About esteban

Esteban is the Founder and Chief Technologist at Nebbia Technology, an ALM consulting and Azure-powered technology company. He is a software developer with a passion for ALM, TFS, Azure, and software development best practices. Esteban is a Microsoft Visual Studio ALM MVP and ALM Ranger, Pluralsight author, and the president of ONETUG (Orlando .NET User Group).

One thought on “Error when installing SQL 2008 on Windows Server 2008 R2 (64 bit)

  1. Mark Allen

    Another approach which works well is to have the XML tag reference a custom TFS group. In my case there is a master contributor group shared between projects so rather than list all the contributor users in the template AssignedTo list boxes I created a TFS group called ‘TeamAssignments’ and within security I referenced the team. Then in the templates I added the tag ListItem value=[project]\TeamAssignments. Now when anyone is added to the team they are displayed in the AssignedTo List box. This also means that another team can be created without changing the templates as the changes can be done in security.

    TFS Team Name: Blue (example set up in security)
    TFS Group Name: TeamAssignments
    Members: Team Blue


Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? *