简体   繁体   中英

Calling another constructor within a constructor

What is the equivalent of the below C# in VB.net?

" 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."

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. See the following reference http://www.harding.edu/fmccown/vbnet_csharp_comparison.html . Its towards the bottom of the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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