what is [] block and how it work?

goodmorningsky

Centurion
Joined
Aug 18, 2003
Messages
172
[System.Diagnostics.DebuggerStepThroughtAttributes()]
public EchoServer(){
...
}

[WebMethod]
public string Echo(string ms){

}

[STAThread]
static void main(){

}

What are those [] block?
I know it's called attribute.. But, I haven't find any article about it..
I need to know syntax, architecture of it..
I haven't seen those from VB, Java...or other language..
Please reply with explanation or any source links..

Thank you all
 
[mshelp=ms-help://MS.MSDNQTR.2003FEB.1033/csref/html/vclrfIntroductionToAttributes.htm]Here we go[/mshelp].

In VB.NET, attributes are put inside < and > characters.

There is also a typo in your first sub, EchoServer; it should be
System.Diagnostics.DebuggerStepThroughAttribute()
 
The attributes (also called decorations as in, "decorate the method EchoServer with the DebuggerStepThroughAttribute attribute") are extra info for the compiler.

There are a bunch of them and you use them for a variety of reasons. For instance, "[WebMethod]" marks a method as a webservice so that the compiler can generate the proper code. You can add simple attributes like Description to describe a property:
C#:
[Description("The Min value")]
public int MinValue
{
// property code would go here...
}

Assuming the above were part of a user control, the "Description" attribute lets the Property window (in design time) show the description.

If you have any attributes particular you have questions about, ask away :)

-Nerseus
 
Thank you .
now I got little clue for that.
It's very strange that I never found former document or book describing about this out of more than 20 .net books and various articles..
 
Other than [WebMethod], you normally won't encounter attributes in many beginner books/tutorials. Not that they're advanced features by any stretch, it's just that there's so much to learn about .NET that they often get overlooked.

-ner
 
That's true..
As more I learn .net, I face more deep and wide concepts of Computer science.
There are nothing to throw out from what I learn from school; network, security, grammer, oop, Soft engineering, graphic, math, algorithms.......

If anyone study computer science now, never look down what you are learning from class room!!!
Even though you don't feel it's necessary, those will be stable corner stone for your life span compurter science career..
 
Back
Top