C# Trivia Test Answers – Part 11

C# Trivia Test - Part 11

(My initial set of responses vanished into the bit bucket due to the wonder that is on-line blog editing, so you'll have to do with the following, absent most of the humor and wittiness that was present in the first version)

Here we go, with the last installment of the series...

Language Details

1) How is decimal different from other C# types?

Decimal is from Mars, int is from Venus. Or perhaps it's the other way around.

Try the following experiment:

a) Write a short C# program that adds two integers.

b) Look at the generated IL.

c) Do the same thing with two decimals.

The difference is that decimal is implemented as a user-defined type, while types like int have specific opcodes devoted to them.

2) What kind of constructor is not legal on structs? Why?

A default constructor. Why? Because in some interop scenarios, the runtime needs to create structs, but it has no way of running any managed code.

At least that's what I heard...

3) What’s the difference between “out” and “[out]”?

One has brackets around it, the other doesn't.

I'm surprised nobody got that one.

If you're looking for another difference, "out" is all about definite assignment, and lets you skip initializing a variable that is passed by reference, while "[out]" is a directive telling the marshaler what to do.

4) When you write ulong, what does the runtime see?

Throatwarbler Mangrove.

Or, perhaps it's System.UInt64. Definitely one of those.

(extra credit: Discuss, without any websearches, the relation of the above reference to naval ambitions.)

C# and the Runtime

5) What interfaces does foreach use in C# 1.1? What about 2.0?

IEnumerable, IEnumerator. IEnumerable<T>, IEnumerator<T>.

Extra credit: Why is the generic version of this so much cooler?

6) What is the name of the attribute that controls the usage of an attribute?


C# and other Languages

7) C# and C++ programmers are at a party (okay, it's a really a user-group meeting). The mood is too nice. What topic do you bring up?

Well, I would bring up deterministic finalization, otherwise know as the "why can't you run my destructor when my variable goes out of scope?" question.

Real Trivia

8) What is chapter 11 of the C# Language spec?

There are two answers to this question. One is "structs", the other is something I'm too lazy to look up right now.

(extra credit: explain why there are two answers.)

9) For a while, C# had a mascot. What was his name? Extra points for his full name.

His name is Andy. No credible evidence has been found to document his first name, but some sources list it as "Angry".

10) What is my most useless computer-related skill? Hint: It's not my rudimentary knowledge of 6502 assembler.

Back in my formative years, I got up extra early in the morning to back up my university's data center. Months of careful practice led to me mastering the art of mounting a backup tape with one hand - and this wasn't just the "put it on the machine with one hand", it was the full "pop off the outer tape ring, put it on the spindle and hit the load button faster than you can say "Bob's your uncle"".

And then, with more months of practice, I progressed to to a new level, when I was able to do that with both hands simultaneously.

It wasn't very useful 2x years ago, so it's certainly not useful now...

Power Users

11) Why does the compiler put "nop" (ie no op) instructions in my IL?

On some systems, you can encounter synchronization issues if one process runs significantly faster than another. The compiler therefore contains an analysis engine that looks at your code, and if it is especially fast, inserts some nop instructions to slow the speed to down to a safe level.

So, consider this a compliment by the compiler about the code that you wrote.

Or, perhaps it has something to do with giving the debugger a place to put a breakpoint. I forget.

12) I have an extraordinary power. I can diagnose problems with P/Invoke statement psychicly. You're having a problem, you come to me, and I say, "Change the <x> in your definition to <y>". And I'm right, about 83% of the time.

What is <x> and what is <y>?

<x> = "messed-up word"
<y> = "the right word"


<x> = "long"
<y> = "int"

In C++, "long" means 4 bytes. In C#, it means 8 bytes. Using long when you mean int makes the runtime angry.

Ancient History

13) Which one of these was a C# codename before disclosure:
a) Awesome!
b) C+++-
c) C-Sure
d) Safe-C
e) C how quick I can write code now!
f) The C clearly system

"d" is the correct answer, and is one of two names used on C#.

I'm sworn to never reveal the other codename. I've thought many times about writing about it any way, because it would make a great story. I've even started to write a post.

But in the end, I decided that doing that wouldn't be cool.

14) C# was first talked about widely at a PDC. What year was it? Where was it held, and how hot was it?
a) 98 degrees
b) Hotter than a jalapeno in a heat wave
c) Hot enough to make your palms sweat at 7:00 AM
d) Hot enough to lose 20 pounds in 20 days, ask me how!

Reliable sources suggest that the year was 2000, and that it was held in a hotel steam bath. Others suggest that it was held in Orlando, and further others maintain that there is no practical difference between the two, except that in the hotel steam bath you may ask the attendent to fetch you a drink.

As for how hot it was, all four answers are correct, though the first one is a bit of a underestimation.

Why Orlando in July? Well, unless you know exactly when your software will be done, it's hard to book early enough to get a nicer venue.

Comments (16)

  1. (From memory)

    No – my name is spelt "Luxury Yacht" but it’s pronounced "Throatwarbler Mangrove"!

  2. Jon Skeet says:

    5) No need for runtime casting or boxing? Ability to use iterator blocks?

    8) There are at least two other answers: "types" and "lexical structure". They are what you get if you look up chapter 11 in the ECMA standards. (The numbering has changed for the third edition, i.e. C# 2.0)

    13) Go on, it was Java++ wasn’t it? 😉

  3. Ryan Heath says:

    13) It had to be ‘cool’! I was missing it in the answers, but your reading your answer now, it definately has to be ‘cool’! 😀

    // Ryan

  4. leppie says:

    11. I have seen/used something similar to tweak the compiler behaviour if the effect is undesired.



     // gaurenteed to run first




     // gaurenteed to run last


    The first part doesnt actually need to be in the try bit, it can be before it. 🙂

  5. TheMuuj says:

    I respectfully disagreee about the answer for #5.  In my tests, the only interface *actually* used is IDisposable, and it’s not even required.

    I have an example program that shows this behavior:


    Notice that neither form of IEnumerable or IEnumerator are used.

    I believe this example also works in .NET 1.0.  Generics were not even needed in order to have a type-safe enumerator that did not box the results temporariliy.  Strings made use of this feature.  Generics (and especially iterators) just makes it a lot easier to write a type-safe enumerator.

    However, other languages may require the interface, so it’s a good practice to declare the interfaces.

    As for why the generic version is much cooler, I’d say because it requires IDisposable to be implemented, which avoids the extra casts and calls to IDisposable that almost always did nothing.  Now, the call will likely be directly to an empty method, and it will be inlined away by the JIT.

  6. ericgu says:


    The question does not ask whether interfaces are required for use with foreach.  They are not required – though as you indicate, you need to put them in for other languages.

    The questions asks what interfaces foreach uses, and those are the ones I list.

    The 1.0 compiler has a pattern-based approach so that you don’t have to box when you foreach over something that returns a value type.

    And that would have been a better question to ask…


  7. TheMuuj says:

    At first glance it it seems like the pattern matching means that the compiler’s "foreach" support did not have to change much between 1.1 and 2.0 in order to support IEnumerable<T>.  As I see it, the same compiler code that build calls to "String.GetEnumerator()" and "CharEnumerator.Current" would work fine for "IEnumerable<Foo>.GetEnumerator()" and "IEnumerator<Foo>.Current".

    However, IEnumerable<T> *can* be explictly implemented, which means there is no public GetEnumerator() method for the compiler to pattern-match against, so the compiler *will* actually use the interface in that case.  In that I mean the resulting IL will actually cast to the interface and then enumerate, where as most of the time the interface is not used and a virtual call is avoided if possible (especially in the case of List<T>).

    To be fair, many trivia questions usually have some kind of "trick" to them, so I was understandably overthinking your question.

    I’d also like to point out that the compiler also avoids the interface (and the pattern) completely in the case of arrays, where a normal "for" loop is compiled, which in turn is specially optimized by the JIT to remove bounds-checks.

    So "foreach" is a very cool language feature that generally tries to perform as well as possible.

  8. Gus says:

    Eric, remember WebC? I think that lasted for one slidedeck maybe?

  9. Karl says:

    Good design!

    [url=http://cqvzuaij.com/hhmz/ooor.html]My homepage[/url] | [url=http://gudsseqs.com/hkug/dlhv.html]Cool site[/url]

  10. EricLee says:

    C# Trivia Test Q

Skip to main content