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

问题描述

如何在类中创建对象数组?当我按照以下方式执行此操作时,我收到一条错误消息:''对象引用未设置为对象'

实例'。


公共类犯人

私有strName为字符串

私有strSSN为字符串

私有strDOB为字符串

私人myMugshotPicture()如MugshotPicture

结束班级


公共类MugshotPicture

私人strPictureName字符串

私人strDateTaken为字符串

结束类

How would I create an array of objects inside a class? When I do it the
following way I get an error that says: ''Object reference not set to an
instance of an object''.

Public Class Inmate
Private strName As String
Private strSSN As String
Private strDOB As String
Private myMugshotPicture() As MugshotPicture
End Class

Public Class MugshotPicture
Private strPictureName As String
Private strDateTaken As String
End Class

推荐答案









将您提供的代码放在类库项目中并编译这个

不会产生任何错误,我猜你在尝试从其他代码中引用myMugShotPicture时会发现错误吗?

在尝试时,你是否用实际的

MugshotPicture对象变量填充了数组?如果不是,那就是你的问题。


-

Peter [MVP视觉开发者]

所有行业的杰克没有人。



As putting the code you provide in a class library project and compiling it
produces no errors, I''ll guess you''re getting the error when attempting to
reference myMugShotPicture from other code?
At the time of the attempt, have you populated the array with actual
MugshotPicture object variables? If not, that''s your problem.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.




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

10-22 19:41