Skip to content
Discussion options

You must be logged in to vote

As you saw, extensions are lowered to normal methods in the extension class. And normal C# rules about overload resolution apply. This means that multiple methods with the same parameter-set "signature" can't exist. And in your case, From(byte) -> ushort and From(byte) -> uint have the same parameter-set. It's the same reason this doesn't compile:

public static class LegacyExtensions
{
    public static ushort From(byte x) { ... }
    public static uint From(byte x) { ... }
}

You need the extension for ushort to be in a separate extension class than that of uint.

You'd need to do this:

using System;
using System.Numerics;

public static class UShortExtensions
{
    extension(ushort)
    {
…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TheBrambleShark
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants