seetharaman
seetharaman

Reputation: 27

How to convert object to a string array in vb.net?

In my code I store a string array as an object inside a dictionary. Because that dictionary is a <string,object> type when I retrieve the value from dict like dict.item("string") it gives me only an object (obviously) but I need a string array. How to take it back now ?

I have seen many questions here, they are like object array to string array, some are same of mine but in java, I need a one line code in Vb.net

edit : code which stores the string array in to the dictionary string_array[2] = {username, new system.Net.NetworkCredential(string.Empty, password).Password} ; out_Config(row("Name").ToString) = string_array

Upvotes: 1

Views: 6915

Answers (1)

theduck
theduck

Reputation: 2617

If you can't modify the dictionary to hold string arrays instead of objects (because it also holds other types) then you can cast the values back to string arrays from objects:

Dim dict As New Dictionary(Of String, Object)
dict.Add("item", New String() {"1", "2"})

Dim stringArray = CType(dict("item"), String())

Upvotes: 3

Related Questions