2010-01-12 89 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