Code Quiz!

C# Puzzle : Reachable goto pointing to an unreachable label

Answer:
Code:
 bool jumping = false;
    try
    {
        if (DateTime.Now < DateTime.MaxValue)
        {
            jumping = (Environment.NewLine != "\t");
            goto ILikeCheese;
        }

        return;
    }
    finally
    {
        if (jumping)
            throw new InvalidOperationException("You only have cottage cheese.");
    }
ILikeCheese:
    Console.WriteLine("MMM. Cheese is yummy.");

Quite an interesting piece of code :) Here's the original at StackOverflow (with an explanation from Eric Lippert)
 
Interesting collection behavior.

When accessing a Hashtable, you don't need to check if the item exists, it has a automatic add/update property.
Code:
using System.Collections;
Hashtable h = new Hashtable();
h["NewKey"] = "Hi Again";

MSDN "You can also use the Item property to add new elements by setting the value of a key that does not exist in the Hashtable... However, if the specified key already exists in the Hashtable, setting the Item property overwrites the old value."

The same behavior exists with the Dictionary<>
Code:
using System.Collections.Generic;
Dictionary<string, string> d = new Dictionary<string, string>();
d["NewKey"] = "Hi";

This is cool as you don't need to check if the item exists before you add/update it. Obviously when accessing the items, you'll need to check it exists to avoid KeyNotFound and NullReference exxeptions.
 
Lol i'm sorry for this but i am gonna ask you guys a question now. :) breaking the rhythm of the thread.:p

But i have a huge question, i did IT in Grade 10 and 11, was the only girl in the class and i was really good (top in the class) then in Grade 12 they told us we no longer have any IT teachers at school and our IT lessons will stop meaning we had to switch over to CAT:mad:. I was very pissed off much to say. So now i would like to know if it's a good idea to study in the IT field next year? i really want to but i'm scared i might suck at it when i start again:D

P.S : Sorry once again but i had to ask as it seems you guys would be able to help me.:D
 
Lol i'm sorry for this but i am gonna ask you guys a question now. :) breaking the rhythm of the thread.:p

But i have a huge question, i did IT in Grade 10 and 11, was the only girl in the class and i was really good (top in the class) then in Grade 12 they told us we no longer have any IT teachers at school and our IT lessons will stop meaning we had to switch over to CAT:mad:. I was very pissed off much to say. So now i would like to know if it's a good idea to study in the IT field next year? i really want to but i'm scared i might suck at it when i start again:D

P.S : Sorry once again but i had to ask as it seems you guys would be able to help me.:D

There have been lots of threads in the last month about this, if one of those don't help you maybe start a new one your specific problem.
 
Top
Sign up to the MyBroadband newsletter
X