如何从vb.net中的对象类继承
我从对象类继承,我的类Clsmatrizdb来处理一个数组(,);但是,当我这样做时,它会产生以下内容
public objPubMatriz as clsMatrizDb(,)
objPubMatriz (0,0) = 1
,我会收到一个错误,说您不能从整数转换为clsxarraydb,
我的班级正在继承这样的
Public Class clsMatrizDb
Inherits Object
Private vIntRow As Integer
Private vIntColumn As Integer
Public Sub New()
MyBase.New
Me.vIntRow = 0
Me.vIntColumn = 0
End Sub
Public Sub New(ByVal pvIntRow As Integer, ByVal pvIntColumn As Integer)
Me.vIntRow = pvIntRow
Me.vIntColumn = pvIntColumn
End Sub
End Class
班级?
I inherit from an Object class, my class clsMatrizDb to handle an Array(,); but when I do it generates the following
public objPubMatriz as clsMatrizDb(,)
objPubMatriz (0,0) = 1
I get an error saying that you can't convert from integer to clsXArrayDb
My class is inheriting like this
Public Class clsMatrizDb
Inherits Object
Private vIntRow As Integer
Private vIntColumn As Integer
Public Sub New()
MyBase.New
Me.vIntRow = 0
Me.vIntColumn = 0
End Sub
Public Sub New(ByVal pvIntRow As Integer, ByVal pvIntColumn As Integer)
Me.vIntRow = pvIntRow
Me.vIntColumn = pvIntColumn
End Sub
End Class
I'm missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的评论最终太长了,所以这是我的解释者:
我同意清理发表的评论。
您已经表示,错误是从整数转换为clsxarraydb,但您根本没有提及此类。你是说clsmatrizdb吗?
您遇到的错误是因为您正在尝试将整数值分配给clsmatrizdb类型的实例(对象)。
如果要创建一个用行和列值初始化为0,0的Clsmatrizdb的实例,那么您只需要声明:
如果要创建具有不同行和列值的Clsmatrizdb的实例(例如2和4),则会声明:
要能够为您的clsmatrizdb对象分配一个整数值,您要么需要默认属性,如tntinmn ...所述,这覆盖了您需要拥有一个行和列值的构造函数。您将代码:
将默认属性声明为:
您将作为本属性实施的一部分设置Vintrow和Vintcolumn的值。
如果要保留参数化的构造函数,则需要在类中添加一个值属性:
使用:
My comments ended up too long, so here's my explainer:
I agree with cleaning up comments made.
You have stated that the error is converting from integer to clsXArrayDb but you don't mention this class at all. Do you mean clsMatrizDb?
The error you are getting is because you are trying to assign the integer value, 1 to an instance (object) of type clsMatrizDb.
If you want to create an instance of clsMatrizDb with Row and Column values initialised as 0, 0 then you just need to declare:
If you want to create an instance of clsMatrizDb with different Row and Column values (for example 2 and 4) then you would declare:
To be able to assign an integer value to your clsMatrizDb object, you will either need a default property as described by TnTinMn... which overrides a need for you to have a constructor that takes the Row and Column values. You would code:
The default property would be declared as:
and you would set the values for vIntRow and vIntColumn as part of this property implementation.
If you want to keep the parameterised constructor then you will need to add a Value property to the class:
With usage: