Tristan
Tristan

Reputation: 6906

What does /*!*/ mean in C#?

I'm new to C# and am reading code with /*!*/ in what seem like strange places. For instance class methods defined as:

protected override OptionsParser/*!*/ CreateOptionsParser()
protected override void ParseHostOptions(string/*!*/[]/*!*/ args)

Unfortunately /*!*/ is not googleable. What does it mean?

Upvotes: 31

Views: 2595

Answers (7)

Rubens Farias
Rubens Farias

Reputation: 57996

It's just a delimited comment; probably your programmer just marked that points to discuss later.

Upvotes: 1

nicerobot
nicerobot

Reputation: 9235

I don't know about C# specifically, as it might be a special notation for something, but i use a similar technique in any language that supports open/close, multi-line comment tokens to allow me to quickly comment and uncomment multiple lines with a single character change, like so:

/*!*/
this is live code (and will probably cause a compilation error)
/*!*/

/*!* /
this is commented code (and should never cause a compilation error)
/*!*/

The reason for the ! is because constructs like /** are common tokens used by documentation tools.

There are other techniques as well when the language supports single-line comment tokens, // (and implements them like C++ and Java):

///* - opening comments can be commented-out so what follows isn't a comment.
this is live code
//*/ - closing comment are not commented-out by single-line comments.

So you can then remove the first single-line comment token, //, to produce a kind of "toggle":

/* this is now commented.
this is also commented.
//*/ this line is live code.

Upvotes: 6

Phil
Phil

Reputation: 2181

Like everyone said, it is a comment. Additionally, it seems to me that the '!' is used for demarcation. It seems to aid in identifying points of interest and serves like eye-candy.

Upvotes: 0

JaredPar
JaredPar

Reputation: 755557

It's likely an attempt to get Spec# style annotations into a non-Spec# build. The ! annotation in Spec# means the value is not-null. The author is likely trying to indicate that both the return values, args array and all of the elements in args are always non-null values.

Spec# Link:

Quick Spec# Overview:

Spec# is a .Net language created via a Microsoft Research Project. It is an extension of the C# language which attempts to embed code contracts into the type system. The most prominent are non-nullable types (indicated with ! after the type name), checked exceptions and pre/post conditions.

Upvotes: 47

Samuel Carrijo
Samuel Carrijo

Reputation: 17949

It's a comment with '!'. Probably the programmer wanted to make sure you noticed the first method returned a OptionsParser, and the second one received an array of strings, and not only a string.

You can remove them, and they'll continue to work fine =)

Upvotes: 1

user177800
user177800

Reputation:

/* is start comment
*/ is end comment

everything between is the comment
you can even tell that SO highlights that area as a comment

Upvotes: 0

Jay Riggs
Jay Riggs

Reputation: 53593

It's a comment that contains an '!'

Anything enclosed in an /* */ is a comment which will be ignored when the code compiles.

Upvotes: 19

Related Questions