C# - The ternary operator

Just when I thought I'd got C# syntax sorted, I come across a statement which looks like some sort of alien script language.  So I decided to look it up and see what it's all about. The statement is what's known as the ternary operator. Simply put it's a way of doing an if else statement in one line of code. Making it more readable and I assume more efficient.

Lets say for example we have a function which returns a dataTable, in some cases the dataTable may have a null value, and trying return the it would cause an exception. So we would have to return null in this case.  The usual syntax might go something like.

if (dt == null)

   return dt;

else

  return null;

 

But using the ternary operator we can distill this down to one line:

 

 

return (dt == null) ? null : dt;

 

A lot nicer, once you understand it.  I believe this also works in JavaScript, but I haven't tested it.


Posted by: Dean
Posted on: 11/14/2008 at 6:26 AM
Tags: , , , ,
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Whos Next

Thanks for my friend Kirstin for this post but looks like the hunt is on for who is going to be the next Doctor.

The BBC now has an official story on David Tennant's departure:
http://news.bbc.co.uk/2/hi/entertainment/7698539.stm

The rumor mill has kicked into high gear, and if you're a betting person, here are some published odds, courtesy of Outpost Gallifrey:

WILLIAM HILL ODDS ON NEXT DOCTOR (30th Oct 2008)

5/2 David Morrissey

3/1 Patterson Joseph

6/1 James McAvoy

7/1 James Nesbitt, Robert Carlyle

8/1 John Simm, Rhys Ifans

12/1 Anthony Head

14/1 Alan Davies, Jason Statham

16/1 Nigel Harman, Bill Nighy

25/1 Daniel Radcliffe, Burn Gorman

33/1 Stephen Fry, John Barrowman

20/1 Next Doctor To Be Female

50/1 Christopher Eccleston

Other rumors are out for a whole lot of others, including Catherine Tate, Peter Purves, Sean Pertwee, and so on.  We can expect to see probably every male actor in Britain between the ages of 30 and 70 being suggested, and quite a few of the female ones as well.

To futher add something interesting to the mix Kirstin did some calculations for us: 

Average lifespan of a Doctor: 3.2 seasons
Average # of stories: 20.3
Average # of episodes: 76.4
Average age at first transmission: 41.6
 
Five Doctors were born in London (one was raised in Manchester); two in or near Liverpool, one in Manchester, and two in Scotland (though one -- Sylvester McCoy -- was raised in Ireland).  So the average new Doctor is apparently 42 years old and born in London.
 
I'm looking up stats on some of the rumored Doctors now

Posted by: Dean
Posted on: 11/5/2008 at 1:05 PM
Tags: , , , , , , , ,
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (3) | Post RSSRSS comment feed

Lets get some perspective

Ok I didn't want to do this because basically I'm only perpetuating a quite pathetic story, but here goes.  The number of stupid people who jumped on the shock bus (band wagon) last week regarding Jonathan Ross & Russell Brand, just goes to prove how stupid the general public can be.  And frankly I'm quite scared that mob mentality is still alive and well in this day and age.  How on earth did this story end up on the front pages and headline stories, over 2 weeks after it was first broadcast?  Especially in a week when:

  • There was a massive earthquake in Pakistan killing 160 people
  • A human catastrophe on biblical scales is going on in The Congo
  • Car bombs go off in Spain, Croatia & Quetta killing innocent people

It just seems to me that we are spoon fed rubbish by the media like children, and we get upset by what we're told to get upset by (right on cue).  Why can't people see or are we just becoming headless children living our lives as we're told to?

Wake up you sheep - because of the thoughless action of 30,000+ idiots radio 2 have lost people who have brought happyness into millions of peoples lives.  Lets face it Andrew Sachs is happy with his apology, his grand daughter from what I've seen isn't really in any position to be throwing stones and the people involved have admitted they over stepped the mark.

So can we all get on with our lives? 


Posted by: Dean
Posted on: 11/4/2008 at 3:39 PM
Tags: , , , , , , , ,
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed