Link to home
Create AccountLog in
Avatar of Soluga
Soluga

asked on

C# New Constructors

Hi,
I am changing my application from VB to C#
In my VB Constructor I had...

    Public Sub New()

    End Sub

And

    Public Sub New(ByVal id As Integer)
        Me._id = id
    End Sub

But C# keeps insisting this is not correct, in C# I have...

public New()
{
   
}

public New(int id)
{
    this._id = id;
}

but I get the error saying it must have a return type!

Any ideas?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of p_davis
p_davis

is New the name of the class?
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Soluga

ASKER

Thanks,
The New keyword in VB is used to create an instance of an object
Not a problem, glad to help.