【发布时间】:2014-08-19 17:36:59
【问题描述】:
我找不到我的答案可能是因为我的代码没有有效地编写,而且我可能比现在更难,但这是我的情况。
我有一个包含十进制值数组 (decimal[] difficultyArray) 的类 (orders.cs)。
在这个类中,我有一个返回数组的属性 (public Array DifficultyArray)。
这个类还有一个字段属性 (private decimal productDifficulty)。
在我的 GUI 中,我有一个下拉菜单,列出了困难(简单、中等、困难)。当用户选择一个难度时,我调用一个方法来设置productDifficulty。我试图通过数组/属性来完成这个(我知道代码被破坏了)
newOrder.ProductDifficulty = newOrder.DifficultyArray(0).Value; // broken
这样的工作:
newOrder.ProductDifficulty = 1.0M
数组中的索引 0 为 1.0M。如何将元素 0 中的值分配给属性/字段?
【问题讨论】:
标签: c# arrays properties