覆盖/继承类构造方法... [英] Overriding/Inheriting Class Constructor Methods...

查看:81
本文介绍了覆盖/继承类构造方法...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几年我一直在使用C#进行编程,但现在我正在处理一个项目,我需要在VB.NET中编写所有代码。


我正在尝试用多个可重写的构造方法创建一个类。

问题是我不知道如何在VB.NET中定义一个构造函数,

更不用说继承默认的构造函数了。以下是我到目前为止:


公共类AppSnippets

私有_instances为整数

私有_appProcess As Process

私人_sysProcesses As Process()


Sub New()

Me._instances = 0

End Sub


Sub New(ByVal appProcess As Process)

MyBase.New()

Me._appProcess = appProcess

结束次级

结束班级


我真的不知道是否Sub New()是构造函数。如果是,我需要接受Process参数的

构造函数来首先调用之前的

构造函数。任何帮助和澄清将不胜感激。


carl

I''ve been programming exclusively in C# for the last few years but am now
working on a project where I am required to write all code in VB.NET.

I''m trying to create a class with multiple overrideable contructor methods.
The problem is that I don''t know how to even define a contructor in VB.NET,
let alone inherit the default contructor. Here is what I have so far:

Public Class AppSnippets
Private _instances As Integer
Private _appProcess As Process
Private _sysProcesses As Process()

Sub New()
Me._instances = 0
End Sub

Sub New(ByVal appProcess As Process)
MyBase.New()
Me._appProcess = appProcess
End Sub
End Class

I don''t really know if "Sub New()" is the constructor. If it is, I need the
constructor that accepts the Process parameter to call the previous
constructor first. Any help and clarification would be greatly appreciated.

carl

推荐答案

Carl,

|我真的不知道是否Sub New()是构造函数。

是Sub New是构造函数。

|如果是的话,我需要

|接受Process参数调用前一个

|的构造函数首先是构造函数。任何帮助和澄清都会非常好。

你可以使用MyBase.New来打电话给你父母的构造函数。


你可以使用MyClass.New来调用你的一个构造函数。


例如:


| Sub New(ByVal appProcess As Process)

| MyClass.New()

| Me._appProcess = appProcess

|结束子

|结束课


希望这会有所帮助

Jay


" Carl Fenley" < clfenley-X - @ - X-wcpci.com>在留言中写道

新闻:%2 **************** @ tk2msftngp13.phx.gbl ...

|我过去几年一直在C#编程,但现在是

|在一个项目上工作,我需要在VB.NET中编写所有代码。

|

|我正在尝试创建一个具有多个可重构的构造函数的类

方法。

|问题是我不知道如何在
VB.NET中定义一个构造函数,

|更不用说继承默认的构造函数了。以下是我到目前为止:

|

|公共类AppSnippets

|私有_instances为整数

|私有_appProcess As Process

|私有_sysProcesses As Process()

|

| Sub New()

| Me._instances = 0

|结束子

|

| Sub New(ByVal appProcess As Process)

| MyBase.New()

| Me._appProcess = appProcess

|结束子

|结束班

|

|我真的不知道是否Sub New()是构造函数。如果是的话,我需要



|接受Process参数调用前一个

|的构造函数首先是构造函数。任何帮助和澄清都会非常感激。

|

| carl

|

|
Carl,
| I don''t really know if "Sub New()" is the constructor.
Yes "Sub New" is the constructor.
| If it is, I need the
| constructor that accepts the Process parameter to call the previous
| constructor first. Any help and clarification would be greatly
appreciated.
You can use MyBase.New to call your parent''s constructor.

You can use MyClass.New to call one of your constructors.

For example:

| Sub New(ByVal appProcess As Process)
| MyClass.New()
| Me._appProcess = appProcess
| End Sub
| End Class

Hope this helps
Jay

"Carl Fenley" <clfenley-X-@-X-wcpci.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
| I''ve been programming exclusively in C# for the last few years but am now
| working on a project where I am required to write all code in VB.NET.
|
| I''m trying to create a class with multiple overrideable contructor
methods.
| The problem is that I don''t know how to even define a contructor in
VB.NET,
| let alone inherit the default contructor. Here is what I have so far:
|
| Public Class AppSnippets
| Private _instances As Integer
| Private _appProcess As Process
| Private _sysProcesses As Process()
|
| Sub New()
| Me._instances = 0
| End Sub
|
| Sub New(ByVal appProcess As Process)
| MyBase.New()
| Me._appProcess = appProcess
| End Sub
| End Class
|
| I don''t really know if "Sub New()" is the constructor. If it is, I need
the
| constructor that accepts the Process parameter to call the previous
| constructor first. Any help and clarification would be greatly
appreciated.
|
| carl
|
|


这篇关于覆盖/继承类构造方法...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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