对象数组 [英] Array of Objects

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

问题描述

在vb 6中,你可以创建一个对象数组,但我似乎无法在.NET中解决这个问题。我想你不能做到这一点,但我想知道如果我有3个名为Object1,Object2,

和Object3的对象,我怎么能做到这一点。然后我会做这样的事情


对于n = 1到3

myobject = Object& n

myobject.myproperty =" whatever"

结束

In vb 6 you use to be able to create an array of objects and I can''t seem to
figure this out in .NET. I figured you can''t make this but I was wondering
how I could do it if I had for instance 3 objects named Object1, Object2,
and Object3. Then I would do something like this

For n = 1 to 3
myobject = Object & n
myobject.myproperty = "whatever"
End for

推荐答案

Dim arrObject ()As ObjectName


将arrObject替换为要用于数组的名称,并且

ObjectName应替换为类的名称。这就是全部

就是它。


-

Gerry O''Brien [MVP]

Visual Basic .NET(VB.NET)


" Altman" <否****** @ SickOfSpam.com>在消息中写道

新闻:Oa ************** @ TK2MSFTNGP12.phx.gbl ...
Dim arrObject() As ObjectName

Replace arrObject with the name you want to use for your array and
ObjectName should be replaced with the name of the class. That''s all there
is to it.

--
Gerry O''Brien [MVP]
Visual Basic .NET(VB.NET)


"Altman" <No******@SickOfSpam.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
在vb 6中你使用能够创建一个对象数组,我似乎无法在.NET中解决这个问题。我想你不能做到这一点,但我想知道如果我有3个名为Object1,
Object2和Object3的对象,我该怎么做。然后我会做这样的事情

对于n = 1到3
myobject = Object& n
myobject.myproperty =" whatever"
结束
In vb 6 you use to be able to create an array of objects and I can''t seem
to figure this out in .NET. I figured you can''t make this but I was
wondering how I could do it if I had for instance 3 objects named Object1,
Object2, and Object3. Then I would do something like this

For n = 1 to 3
myobject = Object & n
myobject.myproperty = "whatever"
End for



你的意思是这样的吗?


Dim myobject(2)As Object

Dim n As Integer

对于n = 0到2

myobject(n )=不管 &安培; n.ToString

下一页


Debug.WriteLine(myobject(0))---->无论0

调试.WriteLine(myobject(1))---->无论1

Debug.WriteLine(myobject(2))---->无论2

" ;奥特曼" <否****** @ SickOfSpam.com>在消息中写道

新闻:Oa ************** @ TK2MSFTNGP12.phx.gbl ...
You mean something like this?

Dim myobject(2) As Object
Dim n As Integer
For n = 0 To 2
myobject(n) = "whatever " & n.ToString
Next

Debug.WriteLine(myobject(0))---->whatever 0
Debug.WriteLine(myobject(1))---->whatever 1
Debug.WriteLine(myobject(2))---->whatever 2
"Altman" <No******@SickOfSpam.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
在vb 6中你使用能够创建一个对象数组,我似乎无法在.NET中解决这个问题。我想你不能做到这一点,但我想知道如果我有3个名为Object1,
Object2和Object3的对象,我该怎么做。然后我会做这样的事情

对于n = 1到3
myobject = Object& n
myobject.myproperty =" whatever"
结束
In vb 6 you use to be able to create an array of objects and I can''t seem
to figure this out in .NET. I figured you can''t make this but I was
wondering how I could do it if I had for instance 3 objects named Object1,
Object2, and Object3. Then I would do something like this

For n = 1 to 3
myobject = Object & n
myobject.myproperty = "whatever"
End for



不确定我明白这一点,我不知道如果你明白我在说什么

。假设我有一个包含50个文本框的表单(名称为

txtBox1,txtBox2,txtBox3 ...),我想将text属性设置为hello
$ b加载时$ b。有没有一种简单的方法可以循环使用它。我是FoxPro

程序员,这就是我在foxpro中做的事情


对于n = 1到50

** lcObject是一个带有对象名称的字符串

lcObject =" txtBox" + ALLTRIM(STR(n))

**&是宏替换,这个语句loObject现在是

等于txtBox(n)对象

loObject =& lcObject

loObject.Value =" Hello"

Endfor


有没有办法做到这一点?

" Gerry O' 'Brien [MVP]" < gerry dot obrien at gmail dot com>在消息中写道

新闻:OW ************** @ TK2MSFTNGP12.phx.gbl ...
Not sure I understand this, I don''t know if you understood what I was saying
either. Say I have a form with 50 textboxes on it (with the names
txtBox1,txtBox2,txtBox3...) and I want to set the text property to "hello"
upon loading. Is there an easy way to loop through this. I am a FoxPro
programmer and this is how I''d do it in foxpro

For n = 1 to 50
**lcObject is a string with the name of the object
lcObject = "txtBox" + ALLTRIM(STR(n))
**the & is "Macro Substitution", with this statement loObject is now
equal to the txtBox(n) object
loObject = &lcObject
loObject.Value = "Hello"
Endfor

Is there a way to do this?
"Gerry O''Brien [MVP]" <gerry dot obrien at gmail dot com> wrote in message
news:OW**************@TK2MSFTNGP12.phx.gbl...
Dim arrObject()As ObjectName

用您要用于数组的名称替换arrObject,并且应该用类的名称替换ObjectName。这就是它的全部。

-
Gerry O''Brien [MVP]
Visual Basic .NET(VB.NET)


奥特曼 <否****** @ SickOfSpam.com>在消息中写道
新闻:Oa ************** @ TK2MSFTNGP12.phx.gbl ...
Dim arrObject() As ObjectName

Replace arrObject with the name you want to use for your array and
ObjectName should be replaced with the name of the class. That''s all
there is to it.

--
Gerry O''Brien [MVP]
Visual Basic .NET(VB.NET)


"Altman" <No******@SickOfSpam.com> wrote in message
news:Oa**************@TK2MSFTNGP12.phx.gbl...
在vb 6中你使用能够创建一个对象数组,我似乎无法在.NET中解决这个问题。我想你不能做到这一点,但我想知道如果我有3个名为
Object1,Object2和Object3的对象,我该怎么做。然后我会做这样的事情

对于n = 1到3
myobject = Object& n
myobject.myproperty =" whatever"
结束
In vb 6 you use to be able to create an array of objects and I can''t seem
to figure this out in .NET. I figured you can''t make this but I was
wondering how I could do it if I had for instance 3 objects named
Object1, Object2, and Object3. Then I would do something like this

For n = 1 to 3
myobject = Object & n
myobject.myproperty = "whatever"
End for




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

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