C# Interview Questions
- Does C# support multiple-inheritance?
No. - Who is a protected class-level variable available to?
It is available to any sub-class (a class inheriting this class). - Are private class-level variables inherited?
Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited. - Describe the accessibility modifier “protected internal”.
It is available to classes that are within the same assembly and derived from the specified base class. - What’s the top .NET class that everything is derived from?
System.Object.
Class Questions
- What is the syntax to inherit from a class in C#?
Place a colon and then the name of the base class.
Example: class MyNewClass : MyBaseClass - Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited. - Can you allow a class to be inherited, but prevent the method from being over-ridden?
Yes. Just leave the class public and make the method sealed. - What’s an abstract class?
A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.
Method and Property Questions
Method and Property Questions
- What’s the implicit name of the parameter that gets passed into the set method/property of a class?
Value. The data type of the value parameter is defined by whatever data type the property is declared as.
- What does the keyword “virtual” declare for a method or property?
The method or property can be overridden. - How is method overriding different from method overloading?
When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.
XML Documentation Questions
- Is XML case-sensitive?
Yes.
- What’s the difference between // comments, /* */ comments and /// comments?
Single-line comments, multi-line comments, and XML documentation comments. - How do you generate documentation from the C# file commented properly with a command-line compiler?
Compile it with the /doc switch.
Debugging and Testing Questions
- What debugging tools come with the .NET SDK?
1. CorDBG – command-line debugger. To use CorDbg, you must compile the original C# file using the /debug switch.
2. DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR.
- What does assert() method do?
In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.
- What’s the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.