-1
編輯:解決方案最終只是空檢查。檢查解決方案的最佳答案。LINQ查詢中的空值檢查和處理
我會簡單介紹一下。
Layers
是TestNineGridData
的列表。 TestNineGridData
有一個屬性VectorSource
它有屬性Paths
,這也是一個列表。
Paths
是一個NineGridPath
對象的列表,其中每個對象都有一個Height
和Width
屬性。
我需要在Layers
中找到最大值NineGridPath
Height
和Width
。
這就是我目前正在得到的,但我得到一個NullReferenceException
。
int maxHeightInLayers = (int)Layers.Max(x => x.VectorSource.Paths.Max(y => y.Height));
int maxWidthInLayers = (int)Layers.Max(x => x.VectorSource.Paths.Max(y => y.Width));
我懷疑問題可能是出我內心的lambda表達式,因爲它可以在Paths
可以檢查一個Height
屬性,但我不知道如何解決這個問題。
注意:爲了說明起見,因爲它可能在我的措辭中含糊不清,VectorSource不需要迭代。 VectorSource
有屬性Paths
,而不是其列表元素。
你確定所有的VectorSouces和路徑都_not null_? –
這是可能的!我很迷戀我的LINQ,我錯過了一個明顯的錯誤。儘管從這個應用程序工作了很長時間,但我懷疑VectorSource或Paths是否爲null。 –