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?

AttributeUsageAttribute

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"

Or,

<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-Sured) Safe-Ce) 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 degreesb) Hotter than a jalapeno in a heat wavec) Hot enough to make your palms sweat at 7:00 AMd) 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.