无法使用var访问属性 [英] Can't access property with var
问题描述
您好,
'e'是一个例外,包含DictionaryEntry类型的数据。
'e' is an exception and contain data with DictionaryEntry type.
为什么在foreach循环中我可以'用var而不是DictionaryEntry访问属性(Key和Value)?
Why in foreach loop i can't access to property(Key and Value) with var instead DictionaryEntry?
谢谢
推荐答案
您好,
您确定这是正确的吗?根据我的阅读,例外数据类型为 IDictionary 。
Are you sure that is correct? From what I read, Exception Data is type IDictionary.
参考文献:  https://msdn.microsoft.com/en-us/library/s4ys34ea%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396#Remarks
Ref: https://msdn.microsoft.com/en-us/library/s4ys34ea%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396#Remarks
  ;
引用: "由于 IDictionary< TKey,TValue> 的每个元素都是一个键/值对,
Quote: "Since each element of the IDictionary<TKey, TValue> is a key/value pair,
元素类型不是键的类型或值的类型。相反,
the element type is not the type of the key or the type of the value. Instead, the
元素类型是 KeyValuePair< TKey,TValue> "
element type is KeyValuePair<TKey,TValue>"
至于使用' var '关键字,匿名类型的隐式广告。 阅读示例部分;
As for the use of 'var' keyword, implicit cast for Anonymous types. Read the Example section;
参考:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/关键字/ var
Ref: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/var
希望这会有所帮助:)
Hope this helps :)
这篇关于无法使用var访问属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!