Go to home page mail me! RSS Feed

The uncommon features of C#.

Wednesday, October 31, 2007 1:01 AM

As I've mentioned several times, I've had the pleasure to interview many applicants in my present and past jobs and I've always diverted to the "less used" list of questions that are located somewhere in my brain. It's down pack and set -  that if you have used any of these "less used" features of C#, you've definitely been around or at least done some digging.

Not that these are really required for day to day development, however, it proves that you are experienced and have some love for the game. It proves that you go home and code, research and keep yourself up to date. The pace in which technology is moving these days, one has to be on top of it or you will be left behind. Anyway, here are my favorites and if you don't know them, please take some time to learn what they are and how they can be used - its  a challenge!

 

The readonly keyword modifier.

Question: What is the different between the const keyword and the readonly keyword?

The volatile keyword.

Question: Can the volatile keyword be applied to a value type field?

Question: Is volatile interchangeable with lock?

The checked keyword.

The fixed statement.

Question: Can you use the fixed statement in a safe context.

The yield keyword.

Question: Can it be used in an anonymous method?

The :: Operator

Indexers

The internal access modifier.

 

kick it on DotNetKicks.com

Have Fun!

Your Comments.

  • # re: The uncommon features of C#.

    GravatarConst is inlined by the compiler and therefore must be set before compilation. Readonly can be set at runtime at instantiation.

    I would think volatile can be used with a value type as it signifies that the value of the variable should not be placed in a register. It can be used instead of a lock construct, however they are not equivalent. I wouldn't trust a volatile when strict control over a shared variable is needed in a multithreaded app.

    Would you ever need to use the fixed construct in a safe context? Its pretty much always used when p/invoking, which is not "safe".

    Can't use a yield in an anonymous method... probably has something to do with the yield statement needing a strong rooting. Somebody whose IL is strong can answer that one.

    Non question comments:

    Indexers are pure joy. Never create a custom collection without one.

    Richter says that you should always surround your arithmetic with checked and unchecked in order to communicate your overflow-checking intent to others who may read your code; I can't find much wrong with that.

    If you create a DLL, you use (or should use!) internal to mark those classes and methods that users of your assembly should not access.

    If you name a class in such a way that it masks a namespace, then you don't need the :: operator; you need a smack in the friggen head.

    Left by mcgurk at 11/1/2007 9:52 AM
  • # re: The uncommon features of C#.

    GravatarI think the important part of const vs readonly is you can assign the value in the constructor with readonly.

    Left by jhunter at 11/7/2007 2:55 PM
  • # re: The uncommon features of C#.

    GravatarWow... you gave such information which nobody told till now... I am very grateful thanks...

    Left by custom net development at 9/22/2008 8:27 AM

Your Reply.

Comment Form.

Fields denoted with a "*" are required.

You may also like to leave your email or website.

 
Please add 6 and 8 and type the answer here:

Preview Your Comment.

 
Next entries »