简体   繁体   English

在构造函数中调用另一个构造函数

[英]Calling another constructor within a constructor

What is the equivalent of the below C# in VB.net? VB.net中以下C#的等效项是什么?

" A constructor can invoke another constructor in the same object by using the this keyword. Like base, this can be used with or without parameters, and any parameters in the constructor are available as parameters to this, or as part of an expression." “一个构造函数可以通过使用this关键字在同一对象中调用另一个构造函数。像base一样,它可以使用或不使用参数,并且构造函数中的任何参数都可以用作此参数或作为表达式的一部分。”

public Employee(int weeklySalary, int numberOfWeeks)
    : this(weeklySalary * numberOfWeeks)
{
}

I would suspect: 我会怀疑:

Public Sub New(weeklySalary As Integer, numberOfWeeks As Integer)
    Me.New(weeklySalary * numberOfWeeks)
End Sub

...but this does not work the same. ...但是这不一样。

Me.New is what you call. Me.New是您所说的。 See the following reference http://www.harding.edu/fmccown/vbnet_csharp_comparison.html . 请参阅以下参考资料http://www.harding.edu/fmccown/vbnet_csharp_comparison.html Its towards the bottom of the page. 其朝向页面底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM