0

I've found a limitation when it comes to use extension methods with using static.

Check the following code snippet:

// file: A.cs
namespace Test.A
{
    public static class Extensions
    {
         public static int sum(this int source, int number) => source + number;
    }
}

// file: Program.cs
using static Test.A.Extensions;

namespace Test
{
    public class Program
    {
        public void Main()
        {
             sum(0, 10);
        }
    }
}

sum(0, 10) won't work even when it has been imported with using static: the compiler says that sum doesn't exist in the whole context.

Is there any workaround for this as of C# 7.1 which may not involve a non-extension method overload to sum?

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206

0 Answers0