Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the method keyword used for in C#?

Tags:

c#

keyword

This might be a stupid question, or oversight on my part, but.. If you type 'method' inside an attribute definition, as below:

[method: ]
public class MyClass 

Visual Studio highlights the keyword. It doesn't seem to highlight it outside of an attribute as far as I can tell, and hitting F1 in VS boots you to a 404.

I've never seen this actually used, and I can't find any information on it.

Anyone know what it does?

like image 336
Rob Avatar asked Jul 15 '12 13:07

Rob


People also ask

What is method in C language?

A method is a code block that contains a series of statements. A program causes the statements to be executed by calling the method and specifying any required method arguments.

Can we use methods in C?

The C standard library provides numerous built-in functions that your program can call. For example, strcat() to concatenate two strings, memcpy() to copy one memory location to another location, and many more functions. A function can also be referred as a method or a sub-routine or a procedure, etc.

What are the keyword used in C?

Keywords are words that have special meaning to the C compiler. In translation phases 7 and 8, an identifier can't have the same spelling and case as a C keyword. For more information, see translation phases in the Preprocessor Reference. For more information on identifiers, see Identifiers.


1 Answers

See Disambiguating Attribute Targets (C# Programming Guide).

Basically, it's to disambiguate between attribute applied to a method and attribute applied to the return value.

like image 145
GSerg Avatar answered Oct 02 '22 09:10

GSerg