问题
I need to create a list with different datatypes element, for example:
{{10, 10}, "IT", 1, "Test", {100, 100}, "Test"}
respectively:
{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"
error occurs.
The class where the variable is declared:
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.
Error:
Any help please?
回答1:
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")
来源:https://stackoverflow.com/questions/64538421/how-to-create-a-list-with-different-type-of-data-using-vb-net