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
{
}
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
{
}
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.
module
keyword when used this way applies an attribute to what the .NET Runtime calls a "module". In the vast, vast, vast majority of cases, each assembly has only one module, so most developers don't even know about modules. –
Triangulation © 2022 - 2024 — McMap. All rights reserved.