-
What is the name of the implicit parameter passed into the set method of a property?
value, whose type is the same as the declared type of the property.
How to implement inheritance in C#?
Add a colon after the class name, followed by the name of the base class.
Does C# support multiple inheritance?
Not supported. This can be achieved using interfaces.
Where can protected properties/methods be accessed?
It can be accessed by inheritance or indirect inheritance and subclasses of this class.
Will private members be inherited?
Yes, but it cannot be accessed. So it seems that they cannot be inherited, but in fact they are inherited. (In my opinion, a subclass inherits everything from the parent class. <Thinking in JAVA> says that the subclass object has a complete copy of the parent class object. Instantiating a class is instantiated from the top-level superclass , is a layer-by-layer wrapping structure. The private restricted access method can only be inside the class. This is just an access control. In fact, the subclass object owns everything of the parent class object.)
Please describe the modifier protected internal.
Properties/methods modified by protected internal can only be accessed by its subclasses in the same assembly (Assembly).
C# provides a default parameterless constructor. When I implement another constructor with one parameter, I also want to retain this parameterless constructor. How many constructors should I write in this way?
Two, once you implement a constructor, C# will no longer provide a default constructor, so you need to manually implement the parameterless constructor.
What is the base class common to all objects in C#?
System.Object.
What is the difference between overloading and overwriting?
Overloading provides the implementation of calling a method signature with different parameters. Overriding provides an implementation in a subclass that changes the behavior of a parent class method.
What does virtual mean in a method definition?
Methods modified by virtual can be overridden by subclasses.
Can non-static methods be overridden into static methods?
No, the signature of the overriding method must be consistent with the signature of the overridden method, except for changing virtual to override.
Can private virtual methods be overridden?
No, even private methods in the parent class cannot be accessed in the subclass.
Can a class be prevented from being inherited by other classes?
Yes, use the keyword sealed.
Is it possible to allow a certain class to be inherited, but not allow a certain method in it to be overridden?
Yes, mark this class as public and mark this method as sealed.
What is an abstract class?
A class that cannot be instantiated. Abstract classes generally contain abstract methods, but of course they can also have concrete implementations. An inherited class can only be instantiated after it has implemented all abstract methods of the abstract class.
When must a class be declared abstract?
When this class contains abstract methods, or when the class does not fully implement the abstract methods of the parent class.
What is an interface?
Classes that contain only public abstract methods. These methods must be implemented in subclasses.
Why can't I specify modifiers for methods in an interface?
The methods in the interface are used to define the contract for communication between objects. It is meaningless to specify the methods in the interface as private or protected. They default to public methods.
Can I inherit multiple interfaces?
certainly.
So what if there are duplicate method names in these interfaces?
In this case you can decide how to implement it. Of course you need to be very careful. But there is no problem in the compilation process.
What is the difference between interface and abstract class?
All methods in an interface must be abstract, and method access modifiers cannot be specified. Abstract classes can have method implementations and can also specify access modifiers for methods.
How to distinguish overloaded methods?
Different parameter types, different parameter numbers, and different parameter orders.
What is the difference between const and readonly?
The const keyword is used to declare compile-time constants, and readonly is used to declare run-time constants.
What is the difference between System.String and System.StringBuilder?
System.String is an immutable string. System.StringBuilder stores a variable string and provides some methods for modifying this string.
This article comes from the CSDN blog. Please indicate the source when reprinting: http://blog.csdn.net/thy822/archive/2009/12/23/5060689.aspx
-