简体   繁体   中英

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.

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.

This syntax is needed because IconReference has an "automatically implemented property":

  public int ResourceId { get; set; }

see also https://stackoverflow.com/a/7670854/121309

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