VB.NET阵列多变量? [英] VB.NET Array with multiple Variables?

查看:231
本文介绍了VB.NET阵列多变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能做到具有多个值的数组中Vb.net?

How can i do a Array with multiple Values in Vb.net ?

我要值添加到数组作为像这样: MyArray.Add(文章,小品,价格)以后我要像再次分裂他们:

I have to add values to an array as like this: MyArray.Add(Article, Pieces, Price) and later I want to split them again like:

Label1.Text= MyArray.Article
Label2.Text= MyArray.Price

感谢每一个答案:)!

Thanks for every Answer :) !

推荐答案

做这样的事情:

    Dim myArray As New ArrayList
    myArray.AddRange("Article,Pieces,Price".Split(","c))
    Label1.Text = myArray(0) 'gives you Article
    Label2.Text = myArray(1) 'gives you Pieces
    Label2.Text = myArray(2) 'gives you Price

否则你可以做到这一点使用对象还列表

Or else you can do this using list of objects also

类定义

Public Class book
    Public Article As String
    Public Pieces As Int32
    Public price As Double
End Class

用法

    Dim BookList As New List(Of book)
    BookList.Add(New book() With {.Article = "someArticle", .Pieces = 12, .price = 20})
    BookList.Add(New book() With {.Article = "someArticle2", .Pieces = 6, .price = 20})
    Label1.Text = BookList(0).Article 'gives you Article name in the 0th index
    Label2.Text = BookList(0).Pieces 'gives you Pieces in the 0th index
    Label2.Text = BookList(0).price  'gives you Price in the 0th index

这篇关于VB.NET阵列多变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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