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
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
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; } } Source: https://ru.stackoverflow.com/questions/555142/
All Articles