2

I have a static class having a static method which is an extension method, like this:

public static class N
{
    public static int Plus(this int i)
    {
        return i + 10;
    }
}

When I try to move this class into a class, to be a nested class, compiler reports error.

Why C# has this kind of limitation for extension method, what for? I don't see any danger that a nested class could contain extension method.

Thanks!

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
vik santata
  • 2,989
  • 8
  • 30
  • 52
  • 1
    Beause they (Microsoft) wanted to make them easy to "discover"... They put a bunch of limitations just for this (for example the ext. method must be inside a static class... There is no reason for this other than "it is easier this way to discover it") – xanatos Jun 16 '15 at 07:03
  • As good practice when asking questions, you should include the error you see in the body of the question. You will get better help that way. – J Richard Snape Jun 16 '15 at 07:04

0 Answers0