Search code examples
c#.netfody.net-attributes

What is the "module" keyword in C# .NET?


I am learning C# and came across the keyword module. I would like to know what this module keyword in C# is and how it is useful. For example, consider the below code:

[module: Test]
public class TestAttribute : Attribute
{
}

Solution

  • In your example module is a way to specify the attribute usage, like this:

    [module: CLSCompliant(true)]
    int Method1() { return 0; }
    

    It is also called attribute target:

    The target of an attribute is the entity which the attribute applies to. For example, an attribute may apply to a class, a particular method, or an entire assembly. By default, an attribute applies to the element that follows it.

    For the full list of C# attribute parameters check the official documentation.