多个变量 [英] Multiple Variables

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

问题描述

有没有办法给多个变量(在这种情况下是整数)而不是一次赋值?

Is there a way to give a value to multiple variables (integers in this case), instead of all at once?

例如,我有 Dim aceVal、twoVal、threeVal、fourVal、fiveVal、sixVal、sevenVal、8Val、nineVal、tenVal As Integer 和待定列表框选择,我想分配threeValFourVal 和 SixVal 的所有值都为 -1.

For instance, I have Dim aceVal, twoVal, threeVal, fourVal, fiveVal, sixVal, sevenVal, eightVal, nineVal, tenVal As Integer and, pending listbox selection, I'd like to assign threeVal fourVal and sixVal all values of -1.

我该怎么做?谢谢.

推荐答案

在 vb.net 中没有办法像threeVal=fourVal=SixVal 那样将它们全部分配在一行上.

There is no way in vb.net to assign them all on one line like threeVal=fourVal=SixVal.

如果您需要所有这些变量,那么一次一行是合适的方法.我建议如果 -1 会被大量使用,然后为它创建一个常量并将 var 分配给常量.

If you need all these variables then one line at a time is the way. I would suggest if -1 is going to be used a lot then create a constant for it and assign the var's to the constant.

如果可能,我还会考虑使用数组或集合来存储您的所有值,并使用它们来设置/检索它们的值.这样您就不必在代码中散布 60 个变量.数组和/或集合会更简洁一些.

I would also consider using an array or collection to store all your values if possible and work with them in order for setting / retrieving their values. You then won't have to have 60 variables littered all in your code. Array and/or collection would be a little cleaner.

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

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