tips and tricks

Blog posts tagged 'tips and tricks'

C# Ternary conditional operator – Question mark in an if statement

Sep 9 09

I’m all for shortening the amount of code we write, if it makes it more readable.

One enhancement I make use of in C# is the ternary conditional operator.

Consider the following block of code:

In this example, we can see, the saidHello boolean value would be false,  as the input string actually said ‘hi’ rather than hello.

This could be shortened down to a single line like so (or 2, if we count the input initialisation)

This makes use of the ternary operator.
The ? acts as a ‘then’ and the : acts as an else…

So you can think of it as something like below:

saidHello equals (if input equals hello then) true, else false.

These can of course be nested, as explained in this article, however in my opinion, this kind of defeats the whole point of this from my point of view – to increase readability of code.

Heart, music, diamonds and other cool symbols on Facebook and other things

Jun 24 09

Ever wondered how to get those cool little symbols in wall posts, status updates, messages etc… on Facebook, MySpace, Twitter, etc…?

This kind of thing: ☼ ☻☺ ♪ ♫ ♥

Well…. you can either copy them off this page, or use the key sequence next to them:

To get these to work:

You will need to have Num Lock ON
Also, you’ll need to use the number pad – the bunch of numerical keys on the right of the keyboard (on a pc)

Press and hold the “Alt” key (usually bottom left of your keyboard) followed by a number (see below)
Please note, the symbol will only appear AFTER you release the Alt key.

1 – ☺

2 – ☻

3 – ♥

4 – ♦

5 – ♣

6 – ♠

7 – •

8 – ◘

9 – ○

10 – ◙

11 – ♂

12 – ♀

13 – ♪

14 – ♫

15 – ☼

16 – ►

17 – ◄

18 – ↕

19 – ‼

20 – ¶