下面是我要实现的重点
这是返回列表的两种方法
var tracklist = _sidRepo.GetTrackSidList(request.systemType);// return point no 2
var SidList = _sidRepo.GetAllList();// return the whole sid list
现在的问题是我在tracklist中有Sid对象的列表,我想检查trackId属性是否存在于第二个列表中,而第二个列表的InUse属性为true,如果它为true,我不想再次检查它,然后添加条件TrackId已被检查,然后从tracklist移至下一个trackid。有想法吗?
答案 0 :(得分:0)
不确定您想要什么。但是据我了解,您可以尝试一下
var tracklist = _sidRepo.GetTrackSidList(request.systemType);// return point no 2
var SidList = _sidRepo.GetAllList();// return the whole sid list
// Create a that will track if a trackId has already been checked
var trackIds = new List<int>();
var validTracks = new List<Sid>();
// we create a list of possible ids
var secondListIds = SidList.Select(x => x.TrackId);
// Loop through
foreach(var track in tracklist){
// Check the exit condition
if (trackIds.Contains(track.TrackId))
continue;
// Ok so we havn't seen this track ID before
// We can check if it the Second list contains it
if (secondListIds.Contains(track.TrackId))
// It Does so we add it to the valid Track Ids
validTracks.add(track);
// Finally add the it to the check list
trackIds.Add(track.TrackId);
}