# VBForums CodeBank > CodeBank - C# >  1st 2nd 3rd etc...

## wossname

I have ported conipto's function to C# (mainly for my own practice really  :Smilie: ) with a few modifications.

Its just a function that adds a suffix to a number making it look like "1st", or "657th".  Negative numbers also supported



```
		private String AddOrdinalSuffix(int num)
		{
			//can handle negative numbers (-1st, -12th, -21st)

			int last2Digits = Math.Abs(num % 100);
			int lastDigit = last2Digits % 10;

			//the only nonconforming set is numbers ending in <...eleventh, ...twelfth, ...thirteenth> 

			return num.ToString() + "thstndrd".Substring((last2Digits > 10 && last2Digits < 14) || lastDigit > 3 ? 0 : lastDigit * 2, 2);
		}
```

Can this be done in less code?

----------


## MrPolite

nice job, but I'd avoid conditional if statements. They're just more confusing and at times slower. It's better to have the code a bit longer but more clear in my opinion

----------


## wossname

I thought conditional if's were only slower in VB6 (and therefore VB.Net), aren't they implemented differently in C# / C++?

?:

----------


## wossname

> It's better to have the code a bit longer but more clear in my opinion


I agree, but i was just trying to push the code as far as it would go  :Big Grin:

----------


## MrPolite

> I thought conditional if's were only slower in VB6 (and therefore VB.Net), aren't they implemented differently in C# / C++?
> 
> ?:


hmm actually you're making me confused now :Big Grin: 
someone needs to look this up hehe, maybe you're right

----------


## jmcilhinney

The C# conditional operator is not a function like IIf so is quite efficient in execution.  I would say that, for the sake of clarity, it should only be used with relatively short statements or else written on two lines if possible, e.g.

```
double z = x == 0 ? 0
                  : y / x;
```

----------


## StrangerInBeijing

> only slower in VB6 (and therefore VB.Net)
> ?:


The IL created by the CLR for if statements in vb.net & c# are the same...remember i checked it a while ago.

----------


## jmcilhinney

> The IL created by the CLR for if statements in vb.net & c# are the same...remember i checked it a while ago.


I don't think he means straight If statements, but rather ?: vs IIf.  One is an operator and one is a function so there will be a significant difference in IL.

----------

