What the hell is NaN?

Someone who was doing a code review for me asked me this question, and how it related to .NET development in general. Funny misconception about NaN, it is not just limited to .NET compatible languages, but is actually an enter computer science concept, to represent an invalid file output based on invalid input operands. I have never used it for anything besides floating point calculations.

The code in question was a condition statement that was taking a SPListItem as a parameter, and was used to check whether the item was a double precision floating number. For this NaN was a definitely a good option! Here is the code:

[csharp]

double isDouble(SPListItem ListItem)
{
if (this._yourField == SPFieldType.Number)
{
try
{
string iListName = ListItem[this._somestring].ToString();
return double.Parse(iListName);
}
catch
{
return double.NaN;
}
}
return double.NaN;
}

[/csharp]

I suppose that there are other ways that you could use a custom method to do the same type of test, but this is small and efficient.

Share