gpt4 book ai didi

VB.NET 属性作为 StringDictionary?

转载 作者:行者123 更新时间:2023-12-04 05:36:53 24 4
gpt4 key购买 nike

我正在尝试创建一个类型为 StringDictionary 的新属性,但是当我像 stringdictionary 变量一样使用该属性时,出现错误。
目标是不使用变量,我需要为此使用属性。在幕后,我将 stringdictionary 值保存到全局用户 ID 索引集合。这是创建属性并尝试获取和设置的代码:

Public Property MaxLenDict As StringDictionary()
Get
Return GetFromCollection("MaxLenDict")
End Get
Set(Value As StringDictionary())
SaveToCollection("MaxLenDict", Value)
End Set
End Property

Public Sub ExampleSub()
If MaxLenDict("hello world") = "" Then MaxLenDict.Add("Hello World", "I'm Here")
End Sub

在此代码的 IF 语句中的 ExampleSub“StringDictionary 无法转换为字符串”中获取此错误:
MaxLenDict("hello world")=""

那么我如何成功地制作和使用一个属性作为字符串字典?

最佳答案

您的属性(property)类型为 StringDictionary() (一个数组!),而不是 StringDictionary .

我不确定是否使用 StringDictionary不过,首先建议。该类只是 .NET 的前泛型版本的残余。使用 Dictionary(Of String, String)相反。

关于VB.NET 属性作为 StringDictionary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11818117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com