C# Trivia Test Q&A

转载 2006年05月28日 23:08:00

C# Trivia Test 

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.



Background 1. mvapich2-1.9a rpm -qa | grep mvapich2 wget http://mvapich.cse.ohio-state.edu/downlo...

基于Flexlive.CQP.Framework的C# 酷Q UDP实现

在阅读本文章之前,希望您已经看过这篇文章,这相对理解这个文章要更容易一些:http://www.cnblogs.com/Traceless/p/6010574.html 近期由于项目需要,需要对接...


※问题详情: 写代码过程中,首先解决了主窗体与子窗体之间数据动态联系的问题(非模态化传值加委托事件),但是Listview控件总会添加进一些重复的信息。为此,我想到的办法是:在数据添加之前进行一系列的...

Interview Q&A - Write a C# console application to implement a string replacement function

Requirements Given three strings: input, oldValue and newValue. Look for oldValue in input and repl...

【C#源码】爱流量活动免费领取300M移动流量 Q群验证

【C#源码】爱流量活动免费领取300M移动流量 Q群验证介绍: 软件主要功能是利用移动爱流量活动 抓包实现的整个抽取流量的过程。每个移动用户最多可以获得300M流量 每天最多3次抽奖机会 流量24小时...

Get Started With Continuous Integration For Your .NET (C#) Projects - Test Your Project

In the previous post, the project is able to build when new code is checked in to the SCM.  In thi...
  • jewes
  • jewes
  • 2011-12-31 11:16
  • 1166


二度驯服Trivia烂代码:bjdp.org第13次编程道场即将开始 2014-02-20 伍斌_Ben 北京设计模式学习组 伍斌_Ben在春节前第一次驯服Trivia烂代码,断断续续花...


  • 2011-08-22 14:40
  • 452KB
  • 下载