开发者

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 ov开发者_Go百科erride void ParseHostOptions(string/*!*/[]/*!*/ args)

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


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:

  • http://research.microsoft.com/en-us/projects/specsharp/

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.


It's a comment that contains an '!'

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


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.


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 =)


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


/* is start comment
*/ is end comment

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜