C# Trivia Test – Part 11


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


Language Details


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


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


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


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


C# and the Runtime


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


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?


Real Triva


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


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


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


Power Users


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


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>?


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


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!

Comments (28)

  1. oldnewthing says:

    7) Politics.

  2. Damien Guard says:

    1.  Different from what other types?

    2. A default constructor.  Because structs need to be initialized quickly especially for use in arrays etc.

    3. out is a keyword, [out] is an identifier

    4. UInt64.

    5. IEnumerable to get an IEnumerator.  In .NET 2.0 it uses IEnumerable<T> to get an IEnumerator<T>.

    7. Garbage collection.

    11. To give the debugger something to tie up with source lines where there are no actual executable code.

    14. 2000?

    [)amien

  3. Sachin says:

    12)

    Change string to stringbuilder, strings are immutable.

    13)

    Db (D flat :D)

  4. Raymond: or 7) religion 😉

    Decimal: const Decimal is not supported by IL (like other value types) and C# will convert to static readonly Decimal; which also means the compiler will convert its use to a literal and never reference the original static readonly field again.  If the const Decimal is a public field of a class in a referenced assembly, any changes to the const Decimal in that referenced assembly will not be used unless the client assembly is recompiled.  Other value types do not do this.

  5. Ricky Dhatt says:

    7) Finalization

    8) Structs

    9) Andy the C# Mascot

    14) July 11 2000 in Orlando, FL.  

  6. ericgu says:

    On #1, I meant different from types like int or bool

    Eric

  7. Jeremy D says:

    7) Properties

  8. "10) What is my most useless computer-related skill?"

    The ability to press SysRq without looking.

  9. Matt says:

    6) Syste,.AttributeUsageAttribute

    7) deterministinc finalization :)

    oh and 1) it’s horrifically bloody slow?

    technically every integral and floating point number can have the operators +,-,* and / applied to them where the result is automatically the most precise of the two available.

    decimal breaks this since it won’t play nice with doubles and floats (as they won’t for a neat approximate superset)

    Technically this doesn’t cover char or bool though.

    Just found it (Ithink) it’s the only value type in the int,char,bool,integrals,floats which has instance constructor(s) such as new Decimal(double)

  10. JamesCurran says:

    #12 I have no real idea (Sachin’s sound good), but it does remind me of my experience solving problems on a C++ newsgroup.

    Every now & then, someone will post a problem, adding that the reason they need help is because, while it will fail when the app is run, when they step through it in a debugger, it works fine.   Eventually, I learned to respond "I don’t need to see the code — you are overunning a local array".

  11. 1. It’s not natively implemented in the JIT. (I guess). You could make your own.

  12. 7. Raw computing performance vs. good memory managment

  13. Eric Wilson says:

    #7) Ask whether multiple inheritance is a good thing :)

  14. Richard says:

    7. Partial template specialisation and template meta programming.

  15. Miral says:

    #2 has always annoyed me.  What if I *want* my structs to have a default of "1" in a certain field.  Arg.

  16. Miral says:

    #2 has always annoyed me.  What if I *want* my structs to have a default of "1" in a certain field.  Arg.

  17. ben says:

    1) not a native type

    2) parameterless constructors, I dont know why

    3) ??

    4) System.UInt64

    5) IEnumerable & IEnumerator and IEnumerable<T> IEnumerator<T>

    6) ??

    7) Multiple inheritance

    8 – 12) ??

    13) Safe-C

    14) PDC 98

  18. TheMuuj says:

    1) decimal is the only C# native type that is not a primitive type, and as such the compiler handles constants using a readonly field and an attribute with the binary form of the value.  Also, operators are provided by overloads (where as VB uses its own implementation of those operators, even in .NET 2 I believe).

    2) Default constructors cannot be declared because creating an array of structs would not call this constructor for performance reasons

    3) [Out] only applys to P/Invoke, I believe, and is for use with both references AND pointers

    4) In .NET 2.0: System.UInt64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    5) If possible, foreach tries to not use any interface (it uses static duck typing in order to prevent boxing), save for IDisposable.  However, it does use the IEnumerable/IEnumerator pattern (and the generic versions in .NET)

    6) AssemblyUsageAttribute (which, in a chicken-egg twist, is applied to itself)

    7) Pretty much anything, but especially Templates vs. Generics and/or runtime performance

    8) ?? When the spec declares bankruptcy?

    9) ??

    10) ?? typing on an upside-down Dvorak keyboard?

    11) To allow breakpoints on lines of code that don’t actually do anything (unless you’re talking about release mode, in which case I have no idea since alignment is probably not a big issue)

    12) I’m always saying "int" to "IntPtr", but that problem will only show up on 64-bit machines (too many people adapt the old VB6 API calls, which is WRONG WRONG WRONG since VB6 was 32-bit).

  19. Matthew W. Jackson says:

    Oh, and I believe that #13 is Safe-C, but I also think that Safe-C is now another project unrelated to C#.

  20. Stu Smith says:

    12) Change the "long" to "int" (LONG is 4 bytes in Win32)

  21. 2) Default constructor is not legal because in struct you can’t do instance field initialization. So runtime need default constructor to initialize all instance fields to their default value.

    struct MyStrstrcut

    {

    int i=10 //illegal

    }

    7)C++ and C# nearly share all feature then why not just say

    How java is sucking on exception 😉

    12) Change CALL to CALLVIRT in IL code.

  22. Ahh I forget this one first one

    1)because of its size it requir 2 read instruction for processor ;0)

  23. 1)Decimal require 2 read instruction

    2) Default constructor is not legal because in struct you can’t do instance field initialization. So runtime need default constructor to initialize all instance fields to their default value.

    struct MyStrstrcut

    {

    int i=10 //illegal

    }

    7)C++ and C# nearly share all feature then why not just say

    How java is sucking on exception 😉

    12) Change CALL to CALLVIRT in IL code.

  24. C# Trivia Test – Part 11

    (My initial set of responses vanished into the bit bucket due to the…