0

我的清单:

List<ArtistAndTags> List1 = new List<ArtistAndTags>(); //Contains about 100 elements.
List<ArtistAndTags> List2 = new List<ArtistAndTags>(); //Contains about 70 elements.

我的课:

public class ArtistAndTags
   {
       public string ArtistName { get; set; }
       public List<string> Tags = new List<string>(); //Compare with this list.
   }

我应该在列表之间获取ArtistName每个列表,其中包含.ArtistAndTagsArtistAndTagsTags

4

1 回答 1

0
        List<ArtistAndTags> List1 = new List<ArtistAndTags>(); 
        List<ArtistAndTags> List2 = new List<ArtistAndTags>();

        var intersectedList = new List<ArtistAndTags>();

        foreach (var item1 in List1)
        {
            foreach (var item2 in List2)
            {
                if (item2.Tags.Intersect(item1.Tags).Any()))
                {
                    intersectedList.Add(item1);
                    intersectedList.Add(item2);
                }
            }
        }

        var result = intersectedList.Select(x => x.ArtistName).ToList();
于 2012-10-01T11:23:47.967 回答