...

View Full Version : What does the ? mean in this line of code



baldtrainer
01-25-2006, 02:46 PM
I'm trying to decipher the meaning in this code. The ? is confusing me.

HighPage = (CurrentCoursePage > HighPage) ? CurrentCoursePage : HighPage;

Any help would be greatly appreciated!

Brandoe85
01-25-2006, 03:22 PM
It's using the ternary operator (google it).
This:


HighPage = (CurrentCoursePage > HighPage) ? CurrentCoursePage : HighPage;

Means:
If the CurrentCoursePage is greater than the HighPage then HighPage = CurrentCoursePage else HighPage = HighPage.

It's a short way of saying:


if(CurrentCoursePage > HighPage)
{
HighPage = CurrentCoursePage;
}
else
{
HighPage = HighPage;
}



Good luck;

Kor
01-25-2006, 03:29 PM
could be used also like this:
condition?statement(or function):statement(or function);

and could be used without else{}
condition?statement(or function):null;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum