我希望从字符串数组中定义字符串变量。
x(2) = {"bar","foo"}如何在bar和foo之外创建变量?然后我如何给它们赋值呢?
发布于 2011-12-28 09:39:00
使用字符串(OfDictionary,String )
Dim x() As String = {"bar", "foo"}
Dim dict As New Dictionary(Of String, String)
For Each s In x
dict.Add(s, "your value")
Next您可以非常容易和快速地读/写值:
dict("foo") = "another value"数组值是字典条目的键。每个键都必须是唯一的。
发布于 2011-12-28 09:32:42
使用Dictionary<string, object>
发布于 2011-12-28 09:47:27
在.net中没有像joel建议的那样的关联数组,您可以使用字典
//in c#:
Dictionary<string, string> myDictionary = new Dictionary<string, string>();
myDictionary.Add("bar", "x");
myDictionary.Add("foo", "fooValue");
string barValue = myDictionary["bar"];https://stackoverflow.com/questions/8650940
复制相似问题