Error: Extension methods must be defined in a top level static class (CS1109)

后端 未结 2 1865
情深已故
情深已故 2020-12-11 18:55

I\'m trying to make a countdown program, which I can start and stop and set the value of the countdown to 10 minutes if needed.

But I\'m getting an error I don\'t qu

相关标签:
2条回答
  • 2020-12-11 19:02

    The error message says exactly what's wrong: your IntExt method isn't a top-level static class. It's a nested static class. Just pull it out of MainForm and it'll be fine.

    0 讨论(0)
  • 2020-12-11 19:07

    I know this question is old, but in case anyone else runs into this problem...

    Check to make sure that the keyword "this" is not in the parameter name definition (usually from copy/paste or drag)

    So, replace:

    public static string AddZero(this int i)
    

    with this:

    public static string AddZero(int i)
    

    That should solve your problem.

    0 讨论(0)
提交回复
热议问题