结构问题中的数组 [英] Arrays in structure problem
问题描述
模块模块1
公共结构学生
Dim name As String
Dim marks()As Integer
结束结构
Sub Main()
Dim ocra(2 )作为学生
ReDim ocra(2).marks(2)
ocra(0).marks(0)= 52
Console.WriteLine(ocra(0).marks(0))
Console.ReadLine()
< br $>
End Sub
结束模块
- >当我运行此代码时,我不断收到此错误:
对象引用未设置为对象的实例。
有人可以帮助我这个?
Module Module1
Public Structure student
Dim name As String
Dim marks() As Integer
End Structure
Sub Main()
Dim ocra(2) As student
ReDim ocra(2).marks(2)
ocra(0).marks(0) = 52
Console.WriteLine(ocra(0).marks(0))
Console.ReadLine()
End Sub
End Module
--> When I run this code, I keep getting this error:
Object reference not set to an instance of an object.
Can someone help me with this?
推荐答案
我认为:
当你执行命令时
I think:
When you execute the command
ReDim ocra(2).marks(2)
您只声明ocra( 2 )的大小.marks()为2.使用ocra( 0 )。 marks(),你没有声明!
你替换
you only declare the size of ocra(2).marks() to be 2. With ocra(0).marks(), you did not declare!
You replace
ReDim ocra(2).marks(2)
by
by
ReDim ocra(0).marks(2)
祝你好运! (我不是VB.NET的支持者)。
Have a good luck! (I'm not supporter in VB.NET).
这篇关于结构问题中的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!