好的,我有两个要素:
class Full
{
public string FullId {get; set;}
public List<string> Tapes {get; set;}
}
和
class OptSet
{
public string SetId {get; set;}
public list<string> Tapes2 {get; set;}
}
我需要选择一个Full
Tapes
列表,其中包含OptSet
Tapes2
列表中的所有元素。
我需要在Linq中完成。我试过了
Full currFull = inputFull.Where(f =>
f.Tapes.Contains(OptSet.Tapes2.ToString())).FirstOrDefault();
但这会导致null。
答案 0 :(得分:0)
这有用吗?
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Full full = new Full()
{
FullId = "A",
Tapes = new List<string>() { "1", "2", "4" }
};
List<OptSet> optSet = new List<OptSet>() {
new OptSet() { SetId = "x", Tapes2 = new List<string>() {"1", "2", "3"}},
new OptSet() { SetId = "y", Tapes2 = new List<string>() {"1", "2", "4"}},
new OptSet() { SetId = "z", Tapes2 = new List<string>() {"1", "2", "3", "4"}}
};
List<OptSet> results = optSet.Where(x => full.Tapes.Where(y => !x.Tapes2.Contains(y)).Count() == 0).ToList();
}
}
public class Full
{
public string FullId { get; set; }
public List<string> Tapes { get; set; }
}
public class OptSet
{
public string SetId { get; set; }
public List<string> Tapes2 { get; set; }
}
}