C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.
C Sharp Interviews are getting tough these days as the technology grows faster. To get through the C Sharp interview one needs to update him/herself in a regular manner. Having said that, just before the interview, it is very important to have a quick glance of the reputed C Sharp questions and answers to make yourself comfortable during the interview process. This is where DoAnswers.com helps you in renewing yourself on C Sharp and various other technologies interview preparation.
21. If I return out of a try/finally in C#, does the code in the finally-clause run?
Yes. The code in the finally always runs. If you return out of the try block, or even if you do a ?goto? out of the try, the finally block always runs: using System; class main { public static void Main() { try { Console.WriteLine(\"In Try block\"); return; } finally { Console.WriteLine(\"In Finally block\"); } } } Both ?In Try block? and ?In Finally block? will be displayed. Whether the return is in the try block or after the try-finally block, performance is not affected either way. The compiler treats it as if the return were outside the try block anyway. If it?s a return without an expression (as it is above), the IL emitted is identical whether the return is inside or outside of the try. If the return has an expression, there?s an extra store/load of the value of the expression (since it has to be computed within the try block).
22. Is it possible to have a static indexer in C#?
No. Static indexers are not allowed in C#.
23. Is it possible to have different access modifiers on the get/set methods of a property?
No. The access modifier on a property applies to both its get and set accessors. What you need to do if you want them to be different is make the property read-only (by only providing a get accessor) and create a private/internal set method that is separate from the property.
24. Is it possible to inline assembly or IL in C# code?
No.
25. What are the different ways a method can be overloaded?
Different parameter data types, different number of parameters, different order of parameters.
26. What class is underneath the SortedList class?
A sorted HashTable.
27. What does the keyword ?virtual? declare for a method or property?
The method or property can be overridden.
28. What does the term immutable mean?
The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
29. What happens if you inherit multiple interfaces and they have conflicting method names?
It?s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you?re okay. To Do: Investigate
30. What is an interface class?
Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.