Skip to content

Constructor

sancalle edited this page Oct 14, 2022 · 4 revisions

Visibility

Default/Public

Typescript

class Foo {
    constructor() {
        // initialization here
    }
}

C#

namespace Codeverter
{
    public class Foo
    {
        public Foo()
        {
            //         // initialization here
        }
    }
}

GO

package codeverter

type Foo struct {
}

func NewFoo() *Foo {
	f := Foo{}
	//        // initialization here
	return &f
}

Visual Basic

Namespace Codeverter
    Public Class Foo
        Public Sub Foo()
            ' // initialization here
        End Sub
    End Class
End Namespace

Protected

Typescript

class Foo {
    protected constructor() {
        // initialization here
    }
}

C#

namespace Codeverter
{
    public class Foo
    {
        protected Foo()
        {
            //         // initialization here
        }
    }
}

GO

Protected constructor as converted as PUBLIC

package codeverter

type Foo struct {
}

func NewFoo() *foo {
	f := foo{}
	//        // initialization here
	return &f
}

Visual Basic

Namespace Codeverter
    Public Class Foo
        Protected Sub Foo()
            ' // initialization here
        End Sub
    End Class
End Namespace

Private

Typescript

class Foo {
    private constructor() {
        // initialization here
    }
}

C#

namespace Codeverter
{
    public class Foo
    {
        private Foo()
        {
            //         // initialization here
        }
    }
}

GO

Private constructor as converted as PUBLIC

package codeverter

type Foo struct {
}

func NewFoo() *foo {
	f := foo{}
	//        // initialization here
	return &f
}

Visual Basic

Namespace Codeverter
    Public Class Foo
        Private Sub Foo()
            ' // initialization here
        End Sub
    End Class
End Namespace

Property declaration

If visibility level was added to the constructor parameters, those are converted as properties.

Typescript

class Foo {
    constructor(public bar: string) {
        // initialization here
    }
}

C#

namespace Codeverter
{
    public class Foo
    {
        public string Bar { get; set; }

        public Foo()
        {
            //         // initialization here
        }
    }
}

GO

package codeverter

type Foo struct {
	Bar string
}

func NewFoo() *Foo {
	f := Foo{}
	//        // initialization here
	return &f
}

Visual Basic

Namespace Codeverter
    Public Class Foo
        Public Property Bar As String

        Public Sub Foo()
            ' // initialization here
        End Sub
    End Class
End Namespace