C# interview questions
1 Describe the difference between a Thread and a Process?
2 What is a Windows Service and how does its lifecycle differ from a "standard" EXE?
3 What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?
4 What is the difference between an EXE and a DLL?
5 What is strong-typing versus weak-typing? Which is preferred? Why?
6 Corillian's product is a "Component Container." Name at least 3 component containers that ship now with the Windows Server Family.
7 What is a PID? How is it useful when troubleshooting a system?
8 How many processes can listen on a single TCP/IP port?
9 What is the GAC? What problem does it solve?
10 What is serialization in .NET? What are the ways to control serialization?
11 Does C# support multiple inheritance?
12 What’s the implicit name of the parameter that gets passed into the class’ set method?
13 What’s the top .NET class that everything is derived from?
14 How’s method overriding different from overloading?
15 What is CLR?
16 What is CTS?
17 What is CLS?
18 What is strong name?
19 What is Application Domain?
20 Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.
Events and Delegates in c#
1. What’s a delegate?
A delegate object encapsulates a reference to a method.
2. What’s a multicast delegate?
A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.
3. What’s the implicit name of the parameter that gets passed into the class’ set method?
Value, and it’s datatype depends on whatever variable we’re changing.
4. How do you inherit from a class in C#?
Place a colon and then the name of the base class.
5. Does C# support multiple inheritance?
No, use interfaces instead.
6. When you inherit a protected class-level variable, who is it available to?
Classes in the same namespace.
7. Are private class-level variables inherited?
Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited.
8. Describe the accessibility modifier protected internal.?
It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).
9. C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write?
Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.
10. What’s the top .NET class that everything is derived from?
System.Object.
General Questions
1.Does C# support multiple-inheritance?
No. But you can use Interfaces.
2.Where is a protected class-level variable available?
It is available to any sub-class derived from base class
3.Are private class-level variables inherited?
Yes, but they are not accessible.
4.Describe the accessibility modifier “protected internal”.
It is available to classes that are within the same assembly and derived from the specified base class.
6.Which class is at the top of .NET class hierarchy?
System.Object.
7.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.
8.What’s the difference between System.String and System.Text.StringBuilder classes?
System.String is immutable.
System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
9.What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
10.Can you store multiple data types in System.Array?
No.
11.What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.
12.How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.
13.What’s the .NET collection class that allows an element to be accessed using a unique key?
HashTable.
14.What class is underneath the SortedList class?
A sorted HashTable.
15.Will the finally block get executed if an exception has not occurred?
Yes.
16.What’s the C# syntax to catch any possible exception?
A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.
17.Can multiple catch blocks be executed for a single try statement?
No. Once the proper catch block processed, control is transferred to the finally block .
18.Explain the three services model commonly know as a three-tier application?
Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).
Whats the difference betweeen Structure, Class and Enumeration
Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory. Classes are Reference-Types, means they are stored as a heap on the memory.
Structures are implicitly derived from a class called System.ValueType. The purpose of System.ValueType is to override the virtual methods defined by System.Object. So when the runtime encounters a type derived from System.ValueType, then stack allocation is achieved. When we allocate a structure type, we may also use the new keyword. We may even make a constructor of a structure, but, remember, A No-argument constructor for a structure is not possible. The structure's constructor should always have a parameter.
So if we define the following structure
struct MyStruct
{
public int y,z;
}
and we create a structure type
MyStruct st = new MyStruct();
In case of a class, no-argument constructors are possible. Class is defined using the class keyword.
A struct cannot have an instance field, whereas a class can.
class A
{
int x = 5; //No error
...
}
struct
{
int x = 5; //Syntax Error
}
A class can inherit from one class (Multiple inheritance not possible). A Structure cannot inherit from a structure.
Enum is the keyword used to define an enumeration. An enumeration is a distinct type consisting of a set of named constants called the enumerator list. Every enumeration has an underlying type. The default type is "int". Note: char cant be the underlying data type for enum. First value in enum has value 0, each consequent item is increased by 1.
enum colors {red, green, blue, yellow};
Here, red is 0, green is 1, blue is 2 and so on.
An explicit casting is required to convert an enum value to its underlying type
int x = (int)colors.yellow;
Whats the difference betweeen Structure, Class and Enumeration
Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory. Classes are Reference-Types, means they are stored as a heap on the memory.
Structures are implicitly derived from a class called System.ValueType. The purpose of System.ValueType is to override the virtual methods defined by System.Object. So when the runtime encounters a type derived from System.ValueType, then stack allocation is achieved. When we allocate a structure type, we may also use the new keyword. We may even make a constructor of a structure, but, remember, A No-argument constructor for a structure is not possible. The structure's constructor should always have a parameter.
So if we define the following structure
struct MyStruct
{
public int y,z;
}
and we create a structure type
MyStruct st = new MyStruct();
In case of a class, no-argument constructors are possible. Class is defined using the class keyword.
A struct cannot have an instance field, whereas a class can.
class A
{
int x = 5; //No error
...
}
struct
{
int x = 5; //Syntax Error
}
A class can inherit from one class (Multiple inheritance not possible). A Structure cannot inherit from a structure.
Enum is the keyword used to define an enumeration. An enumeration is a distinct type consisting of a set of named constants called the enumerator list. Every enumeration has an underlying type. The default type is "int". Note: char cant be the underlying data type for enum. First value in enum has value 0, each consequent item is increased by 1.
enum colors {red, green, blue, yellow};
Here, red is 0, green is 1, blue is 2 and so on.
An explicit casting is required to convert an enum value to its underlying type
int x = (int)colors.yellow;
C# Interview Questions, Part 1
1. What’s the implicit name of the parameter that gets passed into the class’ set method? Value, and its datatype depends on whatever variable we’re changing.
2. How do you inherit from a class in C#? Place a colon and then the name of the base class. Notice that it’s double colon in C++.
3. Does C# support multiple inheritance? No, use interfaces instead.
4. When you inherit a protected class-level variable, who is it available to? Classes in the same namespace.
5. Are private class-level variables inherited? Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.
6. Describe the accessibility modifier protected internal. It’s available to derived classes and classes within the same Assembly (and naturally from the base class it’s declared in).
7. C# provides a default constructor for me. I write a constructor that takes a string as a parameter, but want to keep the no parameter one. How many constructors should I write? Two. Once you write at least one constructor, C# cancels the freebie constructor, and now you have to write one yourself, even if there’s no implementation in it.
8. What’s the top .NET class that everything is derived from? System.Object.
9. How’s method overriding different from overloading? When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.
10. What does the keyword virtual mean in the method definition? The method can be over-ridden.
11. Can you declare the override method static while the original method is non-static? No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.
12. Can you override private virtual methods? No, moreover, you cannot access private methods in inherited classes, have to be protected in the base class to allow any sort of access.
13. Can you prevent your class from being inherited and becoming a base class for some other classes? Yes, that’s what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It’s the same concept as final class in Java.
14. Can you allow class to be inherited, but prevent the method from being over-ridden? Yes, just leave the class public and make the method sealed.
15. What’s an abstract class? A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it’s a blueprint for a class without any implementation.
16. When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)? When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.
17. What’s an interface class? It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes.
18. Why can’t you specify the accessibility modifier for methods inside the interface? They all must be public. Therefore, to prevent you from getting the false impression that you have any freedom of choice, you are not allowed to specify any accessibility, it’s public by default.
19. Can you inherit multiple interfaces? Yes, why not.
20. And if 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.
C# Interview Questions & Answers :
1. Does C# support multiple-inheritance?
No.
2. Who is a protected class-level variable available to?
It is available to any sub-class (a class inheriting this class).
3. 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.
4. Describe the accessibility modifier “protected internal”.
It is available to classes that are within the same assembly and derived from the specified base class.
5. What’s the top .NET class that everything is derived from?
System.Object.
6. 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.
7. What’s the difference between System.String and System.Text.StringBuilder classes?
System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
8. What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
9. Can you store multiple data types in System.Array?
No.
10. What’s the difference between the System.Array.CopyTo() and System.Array.Clone() ?
The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.
Microsoft – C# Interview Questionsv
1. How do you inherit from a class in C#?
2. What is .NET Framework?
3. How we handle sql exceptions? What is the class that handles SqlServer exceptions?
4. What is the advantage of serialization?
5. how to fill datalist usinf XML file and how to bind it,code behind language is c#
6. What is the difference between const and static read-only?
7. Is it mandatory to implement all the methods which are there in abstract class if we inherit that abstract
8. Why do I get a "CS5001: does not have an entry point defined" error when compiling?
9. What's the implicit name of the parameter that gets passed into the class' set method?
10. What is indexer? Where it is used explain
11. Does C# support multiple inheritance?
12. When you inherit a protected class-level variable, who is it available to?
13. Are private class-level variables inherited?
14. Describe the accessibility modifier protected internal.
15. What is the implicit name of the parameter that gets passed into the class set method?
16. What's the top .NET class that everything is derived from?
17. How's method overriding different from overloading?
18. What does the keyword virtual mean in the method definition?
19. What is an abstract class?
20. What is the data provider name to connect to Access database?