31

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?

6
  • 4
    ok, this is fun; Why should anybody put such a comment there ? Feb 1, 2010 at 17:41
  • Where did you see this code? Is it part of a tutorial or a project? Maybe auto-generated code?
    – ZoogieZork
    Feb 1, 2010 at 17:42
  • You might want to look for the cause in the editors your predecessors used. Sometimes comments at odd places are used to circumvent parsing-problems of highlighting editors. (Used to be the case with LPC and its #' - lambda syntax)
    – Leonidas
    Feb 1, 2010 at 17:43
  • 10
    Just to be clear, as far as the language is concerned, it means nothing. It is just a comment containing an exclamation mark. But the question of what the programmer who put it there meant by it, is a good one.
    – jalf
    Feb 1, 2010 at 17:55
  • 1
    @DownVoter - the down voter why do you not state why the comment was downvoted? Again StackOverflow developers why can you not add who downvoted the responses or force a reason why it was downvoted?
    – JonH
    Feb 1, 2010 at 19:47

7 Answers 7

47

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.

6
  • 3
    Another way to do this is place Contract.Ensures(Contract.Result<OptionsParser>() != null); in the method, which would ideally show up in the accompanying documentation. Feb 1, 2010 at 17:45
  • @JaredPar: could fill in some more details? What is a #Spec-build? From the answers so far, this is the only one which seems to have a clue on what is going on.
    – jsbueno
    Feb 1, 2010 at 17:47
  • @jsbueno, added a quick overview of Spec#. The best explanation though is at the link I added. Very detailed documentation can be found there.
    – JaredPar
    Feb 1, 2010 at 17:55
  • @JaredPar I didn't downvote you but I really hate how SO does not implement a way even in the activity section to see who downvoted, or force a reason why there was a down vote. Happens to me all the time and of course the downvoter does not explain..
    – JonH
    Feb 1, 2010 at 18:12
  • Spec# is a superset of C# which has constructs for formal specification and allows formal static verificatione (along with additional runtime checks). You can comment out Spec#-specific language constructs (such as !-Types) and get valid C# which seems to have happened in your case. For further information I suggest following Jared's Link. Feb 1, 2010 at 18:12
19

It's a comment that contains an '!'

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

6

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.
1
  • +1: doesn't answer the question, but is a really nasty^Wgreat hack :-) Feb 19, 2010 at 23:26
1

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

1

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

3
  • I've heard of people who make a habit of downvoting every other answer when they submit one - maybe that's what happened here. Feb 1, 2010 at 20:28
  • 1
    This is one of the bad things about stackoverflow- a guy/gal with a mental disorder can do very crazy things here.
    – Phil
    Feb 1, 2010 at 21:11
  • On the other hand, people might have objected to "multiline comment" for a one-character comment. Feb 2, 2010 at 22:07
0
/* is start comment
*/ is end comment

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

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.

1
  • Those brackets sure are interesting!
    – jball
    Feb 1, 2010 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.