Tuesday, August 26, 2008

XML Comments and Nullable data types

I had not worked with XML comments until joining my current employer.  The syntax is pretty simple, and Visual Studio Intellisense handles most of it, but I occasionally find cases where the correct syntax is not obvious.  For example, I needed to change an int variable to a nullable int.  I updated the variable definition to int?, and changed the XML comment <see cref="int"/> to <see cref="int?"/>. This resulted in a compiler warning: “syntactically incorrect cref attribute 'int?'”.  I searched, but could not find a complete listing of the correct syntax for all data types.  Eventually, I found enough examples to learn that nullable data types are listed as Nullable{type name}, like <see cref="Nullable{DateTime}"/>, <see cref="Nullable{Int32}"/>, <see cref="Nullable{Bool}"/>, etc.

No comments: