VS 2015 forces class reassignment as static without clear reasons for me

Error CS1106 The extension method must be defined in a non-generic static class.

what is the cause of the problem, before the class turned as not static

  • In fact, this is a limitation of the language. - Pavel Mayorov
  • Dak studio also clearly wrote the problem is not clear what? - sp7
  • What a friend he began to demand, I did not touch this class - SergD29
  • 2
    @ SergD29 it doesn't matter if you touched the class or not, but extension methods in C # can only be declared in static classes - DreamChild
  • Thanks for the help, fixed, VS lives its life - SergD29

1 answer 1

Taken from MSDN

Extension methods are defined as static methods, but are invoked using the syntax for calling an instance method. Their first parameter determines the type with which the method operates, and the parameter is preceded by the this modifier. Extension methods are in scope only if the namespace was explicitly imported into the source code using the using directive.
The following example shows the extension method defined for the System.String class. Note that this method is defined inside the non-nested, non-generic static class.

namespace ExtensionMethods { public static class MyExtensions { public static int WordCount(this String str) { return str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries).Length; } }