C# Error CS1109 – Extension methods must be defined in a top level static class; {0} is a nested class

C# Error

CS1109 – Extension methods must be defined in a top level static class; {0} is a nested class

Reason for the Error & Solution

Extension Methods must be defined on top level static classes, ‘name’ is a nested class.

Extension methods cannot be defined in nested classes.

Example

The following example generates CS1109 because the class Extension is nested inside the class Out:

// cs1109.cs  
public class Test  
{  
}  
static class Out  
{  
    static class Extension  
    {  
        static void ExtMethod(this Test c) // CS1109  
        {  
        }  
    }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...