Search code examples
c#.netvb.netconstructorcode-translation

Translate C# Ctor to Vb.Net equivalent


I have taken this struct definition from the Windows API CodePack:

public struct IconReference
{
    //...

    public IconReference(string moduleName, int resourceId)
        : this()
    {
        //...
    }

    public IconReference(string refPath)
        : this()
    {
        //...
    }

    //...
}

The problem is I don't understand how to translate those kind of constructors to Vb.Net.

What is exactlly the meaning of that : this()?

When I use an online code translator, it translates it as Me.New(), however, this fails at compilation because that struct does not have a parameterless ctor.


Solution

  • The this() in C# calls the parameterless constructor. Since you don't have a parameterless constructor in C# (and structs can't even contain "explicit parameterless constructors"), you can omit the this().

    And so for the VB.NET code. You can omit the Me.New() code.