2010-01-12 94 views
2

如何獲取EntityKey的值?如何獲取EntityKey的值?

我嘗試:

串x = Customer.EntityKey.EntityKeyValues [0]。價值;

String x = Customer.EntityKey.EntityKeyValues [0] .Value.ToString();

String x = Customer.EntityKey.EntityKeyValues;

String x = Customer.EntityKey.EntityKeyValues.ToString();

結束於: 未將對象引用設置爲對象的實例。

請幫忙。謝謝

+0

在哪一行?他們全部還是隻有一個? – ChrisF 2010-01-12 14:12:36

+1

所以你的一個對象沒有被初始化到內存中......進入調試模式並檢查哪個對象爲空。 – 2010-01-12 14:13:06

回答

3

正如您所報告的,您得到一個Object reference not set to an instance of an object,您可能需要檢查一個null參考;

String x = (Custormer == null ? null : 
       Customer.EntityKey == null ? null : 
       Customer.EntityKey.EntityKeyValues.Length == 0 ? null : 
        Customer.EntityKey.EntityKeyValues[0].Value); 
+0

謝謝你!!!!!!!!!!!!! – noobplusplus 2010-01-13 12:51:28