Skip to content
Discussion options

You must be logged in to vote

No. This does, though:

#nullable enable

public class Foo1 : Foo {
    protected override T? Serialization_Remove<T>(string Value) where T : default { // Note the new where clause here
        return base.Serialization_Remove<T>(Value);
    }
}

public class Foo {
    protected virtual T? Serialization_Remove<T>(string Value) {
        return default;
    }
}

From the docs:

The addition of nullable reference types introduces a potential ambiguity in the meaning of T? in generic methods. If T is a struct, T? is the same as System.Nullable. However, if T is a reference type, T? means that null is a valid value. The ambiguity arises because overriding methods can't include constraints. The …

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@TonyValenti
Comment options

@TonyValenti
Comment options

@CyrusNajmabadi
Comment options

Answer selected by CyrusNajmabadi
Comment options

You must be logged in to vote
1 reply
@333fred
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants