如何使用vb.net创建具有不同数据类型的列表? [英] How to create a list with different type of data using vb.net?

查看:67
本文介绍了如何使用vb.net创建具有不同数据类型的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个具有不同datatypes元素的列表,例如:

I need to create a list with different datatypes element, for example:

{{10, 10}, "IT", 1, "Test", {100, 100}, "Test"} 

分别:

{object, string, integer, string, object, string}

我尝试将其声明为对象列表或使用 Tuple(Object,String,Integer,String,Object,String)但是当我给他们值时,

I have tried declaring it as list of objects or using Tuple(Of Object, String, Integer, String, Object, String) but when I give them the values,

数组初始值设定项的维数过少"

"Array initializer has too few dimensions"

发生错误.

声明变量的类:

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

我使用参数并为其赋值的类:

The class to which I use the parameter and assign the values:

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

我只发送代码中最重要的部分,它们是使用了更多参数的参数,除了这一部分外,它们都可以正常工作.

I am sending just the more important part of the code, they are more parameters used that works perfectly, except this one.

错误:

请帮忙吗?

推荐答案

如果您使用的是上述的旧Tuple语法,则无法按照显示的方式创建新的元组.您必须这样做:

If you're using the old Tuple syntax as above then you can't create a new one in the way you've shown. You have to do:

    respDocs.signature =
        New Tuple(Of Object, String, Integer, String, Object, String)({10, 10}, "IT", 1, "Testing", {100, 100}, "Test Signature")

这篇关于如何使用vb.net创建具有不同数据类型的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆