将 List
以下不编译:
public List<Guid?> foo()
{
List<Guid> guids = getGuidsList();
return guids;
}
最佳答案
这个问题似乎改变了几次,所以我会用两种方式展示转换:
转换 List<Guid?>
至 List<Guid>
:
var guids = nullableGuids.OfType<Guid>().ToList();
// note that OfType() implicitly filters out the null values,
// a Cast() would throw a NullReferenceException if there are any null values
转换 List<Guid>
至 List<Guid?>
:
var nullableGuids = guids.Cast<Guid?>().ToList();
关于c# - 将 List<Guid> 转换为 List<Guid? >,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16212699/