首页 > 解决方案 > 如何在 vb.net 中将对象转换为字符串数组?

问题描述

在我的代码中,我将字符串数组作为对象存储在字典中。因为<string,object>当我从 dict 检索值时,该字典是一种类型,就像dict.item("string")它只给了我一个对象(显然)但我需要一个字符串数组。现在怎么拿回来?

我在这里看到了很多问题,它们就像对象数组到字符串数组,有些和我的一样,但是在 java 中,我需要 Vb.net 中的一行代码

编辑:将字符串数组存储到字典中的代码 string_array[2] = {username, new system.Net.NetworkCredential(string.Empty, password).Password} ; out_Config(row("Name").ToString) = string_array

标签: vb.net

解决方案


如果您无法修改字典以保存字符串数组而不是对象(因为它还保存其他类型),那么您可以将值从对象转换回字符串数组:

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

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

推荐阅读