7

I'm writing a simple compare function with the following signature:

  /// <summary>
  /// Casts two unsigned integers to signed integers and compares them
  /// </summary>
  /// <param name="arg1">Left side of inequality</param>
  /// <param name="arg2">Right side of inequality</param>
  /// <returns>
  /// LESS_THAN if arg1    <----
  /// </returns>
  private static Inequality Compare(uint arg1, uint arg2)

I would like to put literal inequality symbols where the arrow is without triggering the XML parser. How can I do this?

audiFanatic
  • 2,296
  • 8
  • 40
  • 56
  • 1
    possible duplicate of [How do I escape characters in c# comments?](http://stackoverflow.com/questions/4377372/how-do-i-escape-characters-in-c-sharp-comments) – RubberDuck Jan 16 '15 at 01:20
  • Umm... "Escape `pointy brackets` in C# XML comments" and in the question body you ask "/// `LESS_THAN` if arg1 <----"? "Pointy brackets != LESS_THAN. – Arvo Bowen Jul 09 '16 at 23:05

3 Answers3

12

If you want to see it in the documentation above the method itself, then you can't, just write it out in full, it's clearer too.

For all other purposes (like code insight, generated documentation, etc.), you can use the literal

&lt;

Use

&gt;

For greater than.

Willem van Rumpt
  • 6,490
  • 2
  • 32
  • 44
3

I cheat. I use these characters: ≪≫

/// <returns>
/// if arg1 ≪ 0 then return Inequality.EQUAL_TO
/// if arg2 == 2 ...etc 
/// </returns>

Also useful for

/// <summary>
/// Checks if the List ≪ Dictionary ≪ int,string≫ ≫ is valid
/// </summary>

Looks OK in intellisense, in your code and in the VS produced documentation.

I keep a snippet that produces the following line

// ≪≫ ⇒ ◄==► ―― ≤ ≥ ... plus a few other specials

Paulustrious
  • 609
  • 1
  • 11
  • 17
1

I agree that you can't make your raw XML comments look especially pretty, but I usually try to make mine produce good-looking comments in the Object Browser window, and in IntelliSense, without worrying as much about their appearance in the source code. Therefore, I'd probably write your method and comments something like this:

 /// <summary>
 /// Casts two unsigned integers to signed integers
 /// and compares them
 /// </summary>
 /// <param name="arg1">Left side of inequality</param>
 /// <param name="arg2">Right side of inequality</param>
 /// <returns><para>
 /// LESS_THAN iff <paramref name="arg1"/>
 /// &lt; <paramref name="arg2"/>
 /// </para><para>
 /// GREATER_THAN iff <paramref name="arg1"/>
 /// &gt; <paramref name="arg2"/>
 /// </para><para>
 /// EQUAL_TO iff <paramref name="arg1"/>
 /// == <paramref name="arg2"/>
 /// </para></returns>
 private static Inequality Compare(
       uint arg1, uint arg2)
 {
   var int1 = (int)arg1;
   var int2 = (int)arg2;
   return int1 < int2
     ? Inequality.LESS_THAN
       : int1 > int2
       ? Inequality.GREATER_THAN
         : Inequality.EQUAL_TO;
 }  // end: Compare()

In the Object Browser window, this method's documentation would look something like this:

private static ...Program.Inequality Compare(uint arg1, uint arg2)
Member of ...Program

Summary:
Casts two unsigned integers to signed integers and compares them

Parameters:
arg1: Left side of inequality
arg2: Right side of inequality

Returns:
LESS_THAN iff arg1 < arg2
GREATER_THAN iff arg1 > arg2
EQUAL_TO iff arg1 == arg2

Vincent
  • 11
  • 3