简体   繁体   English

Vb.net到C#的转换错误CS0103

[英]Vb.net to C# conversion Error cs0103

VB.net代码

C#代码

I have made a conversion from VB to C# with telerik online converter. 我已经使用telerik在线转换器从VB转换为C#。 And there is an error as indicated in the second picture. 如第二张图片所示,有一个错误。 What are the ways that i can solve them? 我可以通过什么方法解决它们?

There is a Name variable in Ship.cs class. Ship.cs类中有一个Name变量。 But im just think the conversion of syntax is faulty. 但是我只是认为语法的转换是错误的。

My project requires me to fix the codes so that it works exactly like before the conversion. 我的项目要求我修复代码,以使其完全像转换前一样工作。 I do not understand the syntax used in VB. 我不了解VB中使用的语法。

That is a VB "parameterized property" - there is no direct C# equivalent. 这是VB的“参数化属性”-没有直接的C#等效项。 The closest equivalent in C# is to make it a regular method (which is called the same if the original parameterized property only has a 'get'): C#中最接近的等效项是使其成为常规方法(如果原始参数化属性仅具有“ get”,则称为相同方法):

public Ship GetShip(ShipName name)
{
    if (name == ShipName.None)
        return null;
    else
        return _Ships[name];
}

You should convert it to an accessor: 您应该将其转换为访问器:

public Ship this[ShipName name]
{
    get 
    { 
        if(name == ShipName.None)
        {
            return null;
        }
        return _Ships[name]; 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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