将多个字符串分组到一个列表中 [英] Grouping Multiple Strings into a List

查看:58
本文介绍了将多个字符串分组到一个列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>嘿,

我正在制作游戏,您必须能够分组".你们可能会认为分组真的很容易,但是对我来说,并不是那么容易.这个游戏不会顺便保存数据,它只是一个小应用程序.因此,当您执行某项操作(让我们说攻击)时,它会将您的所有内容组合在一起.可以说,您要知道自己的进攻能力如何,它必须将您的敏捷性,力量,防御能力等分组.字符串就像这样

>hey guys,

i am making a game and you have to be able to ''group''. you guys might be thinking that grouping is really easy, but for me, it isn''t so easy. this game won''t save data by the way, it is just a little application. so, when you do something (lets say attacking) it groups all of your things together. lets say, you see how good you are at attacking, it will have to group your agility, strength, defence, etc. the string will be something like this

dim strength as int = 6
dim agility as int = 3
dim defence as int  5



但是我们需要将它们分组为一个列表.您能否将这些分组到一个称为属性"的列表中?



but we need to group these into one, like a list. could you be able to group these into one list called ''attributes''? please help!!

推荐答案

您可以创建一个类或结构来保存这些值,我在下面列出了一个基本结构.

You can create a class or structure to hold these values, i have listed a basic structure below.

Public Structure Attributes
       Private _attack As Integer
       Private _def As Integer

       Public Property Attack() As Integer
           Get
               Return _attack
           End Get
           Set(ByVal value As Integer)
               _attack = value
           End Set
       End Property

       Public Property Defence() As Integer
           Get
               Return _def
           End Get
           Set(ByVal value As Integer)
               _def = value
           End Set
       End Property

       Public Sub New(ByVal att As Integer, ByVal def As Integer)
           _attack = att
           _def = def
       End Sub

   End Structure


尝试使用 List(Of T )类 [ ^ ]
Try to use List(Of T) class[^]
Dim myNumbers As New List(Of Integer)
myNumbers.Add(6)
myNumbers.Add(4)
myNumbers.Add(12)


这篇关于将多个字符串分组到一个列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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