C# Example Tutorials for Some Interview Questions

零下一度
Release: 2017-06-23 14:30:29
Original
1697 people have browsed it

Recently, a friend who was engaged in NET development resigned and wanted me to find him some interview questions related to NET, so as to prepare for new challenges.

I quickly found various collections and test questions that I had searched before, and today I will sort out the basic knowledge about NET.

1. The three major characteristics of object-oriented languages: encapsulation, inheritance, and polymorphism;

2. What are the similarities and differences between interfaces and classes:

Differences:

 ①Interface cannot be instantiated directly.

 ②The interface only contains the declaration of methods or attributes, but does not include the implementation of the methods.

 ③Interfaces can have multiple inheritance, but classes can only have single inheritance.

 ④The expressions have different meanings. The interface mainly defines a specification and calls methods uniformly, that is, specification classes and constraint classes. Classes are the implementation and collection of method functions

Similar points:

 ①Interfaces, classes and structures can all inherit from multiple interfaces.

 ②An interface is similar to an abstract base class: any non-abstract type that inherits an interface must implement all members of the interface.

 ③Both interfaces and classes can contain events, indexers, methods and properties.

3. What are the similarities and differences between abstract classes and interfaces?

 ①Inheritance: Interfaces support multiple inheritance; abstract classes cannot implement multiple inheritance.

 ②Expressed concepts: interfaces are used for specifications, with more emphasis on contracts, and abstract classes are used for commonality, emphasizing father and son. Abstract class is a high degree of aggregation of a class of things, so for subclasses that inherit abstract classes, for abstract classes, it belongs to the "Is A" relationship; while interfaces define behavioral norms and emphasize the "Can Do" relationship , so for subclasses that implement interfaces, compared to interfaces, "behavior needs to be completed according to the interface."

 ③Method implementation: For methods in abstract classes, the implementation part may or may not be given; but for interface methods (abstract rules), the implementation part cannot be given, and methods in interfaces cannot be added. modifier.

 ④Subclass rewriting: Inherited classes have different implementations of the methods involved. The inherited class does not need to rewrite the abstract methods defined by the abstract class, that is to say, the methods of the abstract class can be extended; while for the methods or attributes defined by the interface class, they must be rewritten in the inherited class. Output the corresponding methods and properties.

 ⑤The impact of new methods: In an abstract class, if a new method is added, the inherited class does not need to be used for any processing; for interfaces, the inherited class needs to be modified to provide a newly defined method .

 ⑥Interfaces can act on value types (enumerations can implement interfaces) and reference types; abstract classes can only act on reference types.

 ⑦Interfaces cannot contain fields and implemented methods. Interfaces only contain signatures of methods, properties, indexers, and events; abstract classes can define fields, properties, and implemented methods.

4. The difference between virtual, sealed, override and abstract

 ①Virtual declares the keyword of the virtual method, indicating that the method can be overridden

 ②Sealed indicates that the class cannot be Inheritance

 ③override method of overriding the base class

 ④abstract declares the keywords of abstract classes and abstract methods. Abstract methods do not provide implementation and are implemented by subclasses. Abstract classes cannot be instantiated.

5. What is the difference between override and overload?

Overloading: When a class contains two classes with the same name but different signatures (the method name is the same but the parameter list is different) ) method, method overloading occurs. Use method overloading to provide methods that perform the same semantics but have different functions. (Multiple methods in one class)

Overriding: Used in class inheritance, the implementation of the virtual method of the parent class can be changed by overriding the subclass method. (More than two classes)

6. The difference between structures and classes

 ① Structures are value types, and classes are reference types
 ② Structures do not support free constructors. Destructors are not supported and cannot be modified with protected;
③ Structures are often used for data storage, and classes are mostly used for behavior;
④ Classes need to use the new keyword to instantiate objects, and struct does not need to use the new key Word;
⑤ class can be an abstract class, struct does not support abstraction;

7. Similarities and differences between out and ref

①ref requires parameters to be explicitly initialized before use, out It should be initialized inside the method;

 ②out is suitable for use where multiple return values ​​need to be retrun, while ref is used when the called method needs to modify the caller's reference.

 ③Ref has in and out, out only goes out but not in; (ref can pass the value of the parameter into the function, but out needs to clear the parameter, which means you cannot pass a value from out. Yes, after out enters, the value of the parameter is empty)

8. The difference between value type and reference type

 ①Value type: It is a quantity containing actual data. That is, when defining a variable of value type, C# will allocate a storage area of ​​appropriate size to the variable in a stack manner based on the declared type. Subsequent read or write operations on this variable will be directly performed in this memory area. conduct;

 ②Reference type: A reference type variable does not store the actual data they represent, but stores a reference to the actual data.
The reference type is created in two steps: first create a reference variable on the stack, then create the object itself on the heap, and then assign the handle of this memory (also the first address of the memory) to the reference variable;

9. What is unboxing and boxing

Boxing→convert value type to reference type, unboxing→convert reference type to value type .

10. What are the performance impacts of boxing and unboxing? How to solve it?

 ①Impact: Both involve memory allocation and object creation, which have a large performance impact;

 ②Solution: Use generics

11. What is delegation? ? Is the event a commission?

 ①Delegate: similar to a function pointer in C or C++, allowing methods to be passed as parameters; (you can substitute one method as a parameter into another method)

 ②Events are special Delegation, events are internally implemented based on delegation;

12. Can the Constructor be inherited? Can it be overridden?

Constructor cannot be inherited, so it cannot be overriding (Overriding), but it can be overloaded (Overloading).

13. Can the String class be integrated?

The String class is a final class so it cannot inherit the string class.

14. When a thread enters a method of an object, can other threads enter the method?

No, the methods of an object can only be accessed by one thread.

15. Use the most effective method to calculate what is 2 times 8?

 2<<3 (left multiplication, right division)

16. What is the difference between Error and Exception?

Error means that recovery is not impossible, but very difficult. Exception means a practical or implementation problem, which means that the program cannot run normally.

17. What are the similarities and differences between UDP and TCP connections?

 ①TCP is a transmission control protocol. It provides connection-oriented, reliable, byte stream services. TCP provides timeout redial and data verification functions.

 ②UDP is the User Datagram Protocol, a simple datagram-oriented transmission protocol, and an unreliable connection.

18. Usage of new keyword

①new operator is used to create objects and call constructors.

②new modifier is used to hide inherited members from base class members.

③new constraints are used to constrain the types of parameters that may be used as type parameters in a generic declaration.

19. Usage of Using keyword

 ①Reference the namespace;

 ②Create an alias for the namespace or type; (using + alias = including detailed namespace information Specific type)

 ③Release resources (close file stream);

20. Accessibility levels are Which types

 ①Pubic access is not restricted.

 ②protected access is limited to the containing class or types derived from the containing class.

 ③Internal access is limited to the current assembly.

 ④protected internal access is limited to the current assembly or type derived from the containing class.

 ⑤private access is limited to the containing type.

21. The rules for a column of numbers are as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34... To find the 30th digit, use a recursive algorithm.

22. Bubble sort

The above is the detailed content of C# Example Tutorials for Some Interview Questions. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template