0

I am porting a portion of Google Gson (Java) to C#. The public abstract class JsonElement defines the following:

public abstract JsonElement deepCopy();

which can be easily translated into C#:

public abstract JsonElement DeepCopy();

The public final class JsonArray (public sealed class in C#), which extends JsonElement, defines the following:

@Override
public JsonArray deepCopy() {
    //irrelevant code
}

which I attempted to translate into C#:

public override JsonArray DeepCopy()
{
    //irrelevant code
}

However, this produces an error:

'JsonArray.DeepCopy()': return type must be 'JsonElement' to match overridden member 'JsonElement.DeepCopy()'

How do I work around this?

QuaternionsRock
  • 832
  • 7
  • 14
  • you are looking for ["new" modifier](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/new-modifier) – vasily.sib Jun 20 '19 at 02:57
  • 1
    but be aware that this is not _"override"_ - it is _"hiding a member"_ – vasily.sib Jun 20 '19 at 03:00
  • also be aware that `Java` != `C#` so _"translated"_ - is a wrong word. They differ in so many ways, so there is **a lot** of things that just **can't** be translated. You should **rewrite**, not translate. – vasily.sib Jun 20 '19 at 03:04
  • @vasily.sib "**trans·late** *(verb)*: express the sense of (words or text) in another language." No one likes a pedant. – QuaternionsRock Jun 20 '19 at 03:27
  • "**un·​trans·​lat·​able** _(adjective)_: unable to be translated, not translatable" No one likes a snapper – vasily.sib Jun 20 '19 at 03:48

0 Answers0