asp.net - 如何使用 vb.net 创建具有不同类型数据的列表?
问题描述
我需要创建一个具有不同数据类型元素的列表,例如:
{{10, 10}, "IT", 1, "Test", {100, 100}, "Test"}
分别:
{object, string, integer, string, object, string}
我尝试将其声明为对象列表或使用Tuple(Of Object, String, Integer, String, Object, String)
,但是当我给它们值时,
“数组初始值设定项的维度太少”
发生错误。
声明变量的类:
Public Class SignatureResponse
Public signature As Tuple(Of Object, String, Integer, String, Object, String)
Sub New()
Me.signature = Nothing
End Sub
Sub New(ByVal signature As Tuple(Of Object, String, Integer, String, Object, String))
Me.signature = signature
End Sub
End Class
我使用参数并为其分配值的类:
Public Class Signature
Inherits System.Web.Services.WebService
<WebMethod()>
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False, XmlSerializeString:=False)>
Public Function SendIdDocuments(ByVal idDocument As String, ByVal content As String, ByVal userId As String)
Dim respDocs As New SignatureResponse
respDocs.signature = {{10, 10}, "IT", 1, "Testing", {100, 100}, "Test Signature"}
'Other part of development
JSONString = JsonConvert.SerializeObject(respDocs)
Return JSONString
End Function
End Class
我只发送代码中更重要的部分,它们是使用的更多参数,可以完美运行,除了这个。
请问有什么帮助吗?
解决方案
如果您使用上面的旧元组语法,那么您无法按照您显示的方式创建新语法。你所要做的:
respDocs.signature =
New Tuple(Of Object, String, Integer, String, Object, String)({10, 10}, "IT", 1, "Testing", {100, 100}, "Test Signature")
推荐阅读
- ios - 问:在启动屏幕中添加不带@Binding 的关闭按钮
- r - R按组识别数据框更改模式
- javascript - Node.js 常量不等待异步函数的响应
- c - dlsym 导入方法一次供后续使用
- reactjs - 如何在设置 authContext 和登录状态之前等待 cookie。反应,火力基地
- tensorflow - 恢复保存的模型/会话后验证精度差,尽管在训练过程中很好
- protractor - 如何在量角器中转换javascipt
- php - NGINX 和 PHP-FPM (7.4) 在 ubuntu 404 上通过 javascript 访问的 .php 文件
- amazon-web-services - 无法将数组传递给 AWS StepFunction 中的参数
- python - 试图在 tkinter 中打印我的菜单 gui 的总成本。ERROR = 'int' 对象不可调用