What does this attribute [Option (...)] C # mean?

What does this C # attribute mean? I mainly work with C ++, and I know about the concept of attributes in C #, but not sure about this: This is in the class. So basically we have a property and attribute for it.

[Option("h", "help", HelpText = "Shows this help message")] public bool Help { get; set; } 

thanks

+7
c #
source share
2 answers

This is a command line option from one of the console application libraries that helps analyze command line arguments.

It could be from the Command Line Command Line Tool , which has very similar syntax to your example.

+11
source share

Attributes are a way to associate information with your C # code.

For example, if you want to make your method a web method, you will use the webmethod attribute

 [WebMethod] void myfunction() ... 

While working with web services and you want to serialize custom objects, you can apply the serialize attribute

 [Serializable] public class MyObject { public int n1 = 0; public String str = null; } 

if you want to use user32.dll for some window-related tasks, you can import this function using the dllimport attribute as follows

 [DllImport("user32.dll")] extern static void SampleMethod(); 

For more information you can see MSDN

+2
source share

All Articles