在VB.Net中排列对象 [英] Array an Object in VB.Net

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

问题描述

您好所有访客
我在vb.net中数组对象存在问题
我已经创建了班级(班级学生)

Hi all visitors
i have problem with array an object in vb.net
i have created class (class student)

public class student
      private  id as integer
      private name as string
      private gender as string

      public property SetID() as string
          Get
             return id
          end get
          set(Byval value as string)
               id=value
          end set
      end property
     public property SetName() as string
          Get
             return name
          end get
          set(Byval value as string)
               name=value
          end set
      end property

      public function Display() as string
          return id & vbTab & name
      end function
end class


在表单加载事件中,我这样写:
昏暗的obj()作为新学生"如果我像这样声明对象,将导致错误的coz数组不能与"New"一起使用
所以我需要这样声明:


At the form load Event I write like this:
dim obj() as new student'' if i declare object like it will error coz array can''t use with "New"
so i need to declare like this:

dim obj() as student
redim preserve
obj(0).SetID=1
obj(0).SetName="AAA"



如果我这样写,我会错误地说我尚未声明的对象"
我不知道应该在哪里设置学生班级的关键字"New".


请帮助我,如果我想将数组与那样的对象一起使用怎么办?

最好的问候,



if i write like this, i will error say that "The object that i declare not yet set"
I don''t know where should i set key word "New" of my student class.


Please help me, if i want to use array with object like that How i can do?

Best Regards,

推荐答案

首先,为什么要使用数组而不是动态容器?其次,如果您创建对象数组,这并不意味着对象在那里,它们将被设置为Nothing,并且需要在将每个对象添加到数组时创建它们.最后,如果您有错误,请向我们发布实际错误,而不是您对错误的理解.这样,我们就能真正了解发生了什么.
First of all, why use an array and not a dynamic container ? Second, if you create an array of objects, that doesn''t mean that the objects are there, they will be set to Nothing and you need to create each object as you add it to the array. Finally, if you have errors, post the actual error to us, not your understanding of it. That way, we can actually understand what''s going on.


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

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