簡體   English   中英

比較兩種不同類型的列表

[英]Compare two different types of list

我有2種不同類型的列表,需要進行比較。兩個列表都有GUID。

首先,我將向您顯示錯誤。

錯誤10'System.Collections.Generic.List'不包含'Except'的定義,最佳擴展方法重載'System.Linq.Queryable.Except TSource>(System.Linq.IQueryable TSource>,System.Collections.Generic .IEnumerable TSource>)'有一些無效的參數

我的密碼

List<CarViewModel> _GetCarsBeforeMove = icarrepository
    .GetList(x => x.CarId.Equals(interlst.Car2Id) && x.ModelId.Equals(interlst.Model2Id))
    .Select(x => new CarViewModel
    {
        CarId = x.CardId, //This returns this type of Id's list 00000000-0000-0000-0000-000000000001
    }).ToList();

我還有另一個清單,這個清單也有Guid的

List<Guid> _GetCarsAfterMove = new List<Guid>();
_GetCarsAfterMove .AddRange(interlst.IntLst); //List has values

現在,我想比較上面的兩個列表,並獲得差異

var MovedCars = _GetCarsAfterMove.Except(_GetCarsBeforeMove).ToList(); //Above error shows me here

方法Except需要IEnumerable<Guid> ,而不是IEnumerable<CarViewModel>

將最后一行更改為:

var MovedCars = _GetCarsAfterMove.Except(_GetCarsBeforeMove.Select(c => c.CarId)).ToList();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM