从 IList 而不是 IEnumerable (C#) 获取数据

Take data from IList instead of IEnumerable (C#)

当我得到:

public interface Test
{
    IEnumerable<Guid> ModelIds { get; set; }
}

然后投入使用我有:

public IEnumerable<Guid> Test
{
    get => m_data.ModelIds;
    set { m_data.ModelIds = value.ToList(); }
}

然后我像这样使用它:

abc.ModelIds = my_list.Select(x => x.Id);

但是我需要修改界面:

public interface Test
{
    IList<Guid> ModelIds { get; set; }
}

和实施服务:

public IList<Guid> Test

现在怎么取id?

abc.ModelIds = my_list.Select(x => x.Id);

error CS0266: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<System.Guid>' to 'System.Collections.Generic.IList<System.Guid>'. An explicit conversion exists (are you missing a cast?)

我认为问题出在这里。

public IEnumerable<Guid> Test
{
   get => m_data.ModelIds;
   set { m_data.ModelIds = value.ToList(); }
}

而不是 .ToList() 只需使用 m_data.ModelIds = value;

如果它说问题出在这里。

abc.ModelIds = my_list.Select(x => x.Id);

尝试

 abc.ModelIds = my_list.Select(x => x.Id).ToList();