vb.net - 使用 vb.net 的属性、数组和 ArrayLists
问题描述
在我的 Web 项目后面的代码中,我有一个属性
Public Shared UserAttributes(2) As String
Public Property _UserAttributes(ByVal Index As Integer) As String
Get
Return UserAttributes(Index)
End Get
Set(value As String)
UserAttributes(Index) = value
End Set
End Property
我也有一个ArrayList
声明为Friend
Friend UserParameters As New ArrayList
我这样称呼我的财产:
_UserAttributes(0) = "parameter1"
_UserAttributes(1) = "parameter2"
_UserAttributes(2) = "parameter3"
UserParameters.Add(UserAttributes)
_UserAttributes(0) = "parameter1,1"
_UserAttributes(1) = "parameter2,1"
_UserAttributes(2) = "parameter3,1"
UserParameters.Add(UserAttributes)
从上面的代码中,我们可以看到两对属性各有一个文本。
我现在需要的是:
在我将我的三个属性添加Property
到我ArrayList
的属性的后三个属性之后,不要破坏第一个属性。
到目前为止,他们正在做什么
最后我有两个(2)_items
在我的ArrayList
其中每个都有相同的文本_item
(这是最后一个)。
我需要的是编写第二组(或更多)属性,而不会破坏之前_items
的ArrayList
.
解决方案
最后我已经成功解决了这个难题,如下
一个属性ArrayList
Public Property _UserParameters As ArrayList
Get
Return UserParameters
End Get
Set(value As ArrayList)
UserParameters = value
End Set
End Property
第二属性为Array
Public Property _UserAttributes(ByVal Index As Integer) As String
Get
Return UserAttributes(Index)
End Get
Set(value As String)
UserAttributes(Index) = value
End Set
End Property
从后面的代码中我使用以下代码:
Dim UserAttributes As New Hashtable
Dim key As Object = Nothing
Dim Param As Object = Nothing
Dim myList As New ArrayList
Dim item As Object = UserAttributes
UserAttributes.Add("UserId", "Parametr1")
UserAttributes.Add("UserName", "Parametr2")
UserAttributes.Add("UserMail", "Parametr3")
For Each item In UserAttributes
key = item.Key
Param = item.value
logHandler._UserParameters.Add(key & "^" & Param)
Next
myList.Add(logHandler.UserParameters.ToArray)
UserAttributes.Clear()
logHandler.UserParameters.Clear()
UserAttributes.Add("UserId", "Parametr1-1")
UserAttributes.Add("UserName", "Parametr2-1")
UserAttributes.Add("UserMail", "Parametr3-1")
For Each item In UserAttributes
key = item.Key
Param = item.value
logHandler._UserParameters.Add(key & "^" & Param)
Next
myList.Add(logHandler.UserParameters.ToArray)
的使用HashTable
解决了我的问题,随着从HashTable
参数到字符串的转换,
首先将它们添加到ArrayList
属性
中,然后将它们添加到第二个ArrayList
,这些结果ArrayList
我将它添加到Pull Down menu
控件中。
为什么我要这么做?
那是因为我有很多用户具有与键相同的属性但不同的值
大家好,非常感谢。
推荐阅读
- c++ - C++ 抽象类是否需要遵守五法则?
- python - Python将小时-分钟更改为小时结束格式
- php - 类型错误:传递给 Illuminate\Auth\SessionGuard::login() 的参数 1 必须实现接口 Illuminate\Contracts\Auth\Authenticatable
- apache-kafka-streams - 如何为 Transformer 设置 State Store
- ansible - 条件失败时的 Ansible 倍数
- ruby - 如何限制 Sinatra/Active Record 中数据库字符串值的字符/字数?
- vba - VBA 访问消息框问题
- kendo-ui - kendo ui 编辑器如何使用范围对象修改用户选择
- java - 未处理异常的输出与程序的输出混合
- c++ - cpp connect() 函数被无限期阻塞