Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 包含空检查以在列表中查找索引_C#_Linq - Fatal编程技术网

C# 包含空检查以在列表中查找索引

C# 包含空检查以在列表中查找索引,c#,linq,C#,Linq,我是否可以在此代码中包含null检查: var index = someList.FindIndex(p => p.Bla1.Id == Dto.Id || p.Bla2.Id == Dto.Id); Bla1和Bla2都可以为空。谢谢。这个怎么样: var index = someList.FindIndex(p => (p.Bla1 != null && p.Bla1.Id == Dto.Id)

我是否可以在此代码中包含null检查:

var index = someList.FindIndex(p => p.Bla1.Id == Dto.Id || p.Bla2.Id == Dto.Id);
Bla1和Bla2都可以为空。谢谢。

这个怎么样:

var index = someList.FindIndex(p => (p.Bla1 != null && p.Bla1.Id == Dto.Id) 
                                 || (p.Bla2 != null && p.Bla2.Id == Dto.Id));
是的,你可以=)

如果您询问如何做到这一点:

var index = someList.FindIndex(p => (p.Bla1 != null && p.Bla1.Id == Dto.Id) || (p.Bla2 != null && p.Bla2.Id == Dto.Id));

但这一切都取决于您想要如何处理空值

您到底想要检查什么?你想要实现什么?我认为这是不言自明的…误解了你的问题。我知道ID可以是空的,而不是对象。