Interview Questions: C #(2 ),
1. Differences between classes and interfaces
Definition
Class describes an object, including status, attributes, and actions.
The interface defines a type of action without implementation or status information.
From a program perspective
The interface is a function declaration; the class is a function implementation.
The interface can have attributes but cannot have fields.
A subclass can inherit only one parent class, but can inherit multiple interfaces.
2. Differences between interfaces and abstract classes
Abstract classes are highly aggregated for a type of things, and interfaces are the norm for defining behaviors.
When an abstract class defines a method, it can be implemented or not
Methods defined in the interface cannot be implemented
Abstract class subclasses can not override abstract methods. classes that inherit interfaces must have methods and attributes.
3. Differences between abstract and Virtual Methods
Abstract METHODS Use abstract keywords. virtual Methods use virtual keywords.
Abstract methods must be overwritten by Derived classes. Virtual methods can be not overwritten.
Abstract methods can be viewed as virtual methods without implementation.
Class contains abstract methods, which must be defined as abstract classes
4. Equal (), ReferenceEqual (), =
For reference types
Equal is used to compare whether referenced values are Equal.
ReferenceEqual
Object a = new Object ();
Object B =;
Object c = new Object ();
Object d = new Object ();
C = (object) 100;
D = (object) 100;
System. Object. Equals (a, B); // return true
System. Object. ReferenceEquals (a, B); // return true
System. Object. Equals (c, d); // return true
System. Object. ReferenceEquals (c, d); // return false
For the value type, if the value of the operand is equal, the equal operator (=) returns true; otherwise, false. For reference types other than string, if the two operands reference the same object, = returns true. For the string type, = compares the string value.
5. Differences between processes and threads
The unit of CPU scheduling and allocation in a thread. There can be multiple threads in the process to share process resources.
6. Notes for using Operator
Public static modifier is required;
Return values are required. The parameter types can be different. ==and! = Must appear in pairs
7. Difference between Task and ThreadPool
ThreadPool does not support thread cancellation, completion, failure notifications, and other interactions
ThreadPool does not support the thread execution sequence.
Task has attributes. You can query the status when the Task is completed (IsCanceled \ IsCompleted \ IsFaulted)
The Task does not provide a callback time notification. Similar functions are completed by starting a new Task.
ContinueWith can start a new Task when a Task is completed. It supports Task completion notifications and obtains the results of the old Task in the new Task.
ThreadPool can save time consumed by creating and destroying threads, reduce memory waste and performance loss.
8. Role of the Sealed keyword
Classes and Methods Modified by the Sealed class cannot be inherited or overwritten.
9. What interfaces or methods are required to be implemented for objects accessed with foreach traversal?
You do not have to implement the IEnumerable interface. You must implement the GetEnumerator method.
10. Can constructor be overwritten?
No. The constructor cannot be inherited, Override cannot be used, or Overload
To be continue...