在方法调用中,对象被传递给它。
从这个对象中我可以得到两件事:一个 ItemData
属性和一个 Row
属性,例如:
oPTL.ItemData, oPTL.Row
我想要一个数据结构,每次调用此方法时它都可以更新此数据结构,例如一次 oPTL.ItemData
为 "Spread1"
且 oPTL.Row
为 2
所以我们应该能够保存它Spread1
的值为 2
...例如,下一次调用我们应该能够保存“Spread3”的值为 3..下一次调用“Spread1”的值为 4 等...
所以它就像一个 Dictionary>
但我仍然在代码中以这种方式声明和使用它时遇到问题,任何代码示例都可以帮助我 和?
In a method call an object is getting passed it.
From this object I can get two things: an ItemData
propery and a Row
property so for example:
oPTL.ItemData, oPTL.Row
I want to have a data structure that each time this method is called it can update this data structure so for example one time oPTL.ItemData
is "Spread1"
and oPTL.Row
is 2
so we should be able to save that Spread1
has value 2
...next call for example we should be able to save "Spread3" has value 3..next call "Spread1" has ALSO value 4 , etc...
So it is like a Dictionary<String,<List>>
but still I have problem with declaring and using it this way in the code, any code sample you can help me with?
发布评论
评论(2)
您可以使用值为列表的字典:
要填充它,您可以使用此扩展方法:
像这样使用:
You can use a dictionary where the values are Lists:
To populate it you can use this extension method:
Use like this:
您要查找的是
Dictionary> ;
- 假设您的.ItemData
和.Row
属性实际上是string
和int 分别。
当您读取具有“Spread1”值的项目时,首先通过调用
.ContainsKey(string)
方法检查字典中是否已存在该键。如果是这样,您将添加新的Row
值 - 如果没有,您将使用全新列表创建新键,如下例所示:编辑以使用两个
添加说明。添加
方法。What you're looking for is
Dictionary<string, List<int>>
- assuming your.ItemData
and.Row
properties are in factstring
andint
respectively.When you read item with "Spread1" value, you first check whether such key already exists in dictionary by calling
.ContainsKey(string)
method. If so, you add newRow
value - if not, you create new key with brand new list, like in example below:Edited to add clarification with two
.Add
methods.