![](/img/trans.png)
[英]How do I automatically cast a value obtained from FieldInfo.GetValue to the correct type?
[英]Object returned from FieldInfo.GetValue cannot be cast to Array
檢查dynamicProperties
對象的類型,該對象在顯示的調試器屏幕快照中不可見。 最有可能是某種List<>
。
您嘗試的強制類型轉換僅在引用類型數組(例如string[]
或object[]
成功時才會成功,如果該類型是struct,則失敗,如以下問題所示: object to string array
在任何情況下, IReadOnlyCollection<T>
, IReadOnlyList<T>
和IEnumerable<T>
接口都是協變的,您可以嘗試強制轉換為IEnumerable<object>
,或者如果您需要更多信息(例如計數或索引器訪問),請嘗試以下一種其他接口。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.