C # Summary of related interview questions,

Source: Internet
Author: User

C # Summary of related interview questions,

Recently, a friend engaged in NET development left the company and asked me to ask him some questions about NET. He was prepared to meet the new challenges.

I quickly found various previous collections and questions. Today I will sort out basic NET knowledge points.

1. Three main features of object-oriented language: encapsulation, inheritance, and polymorphism;

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

Differences:

① The interface cannot be directly instantiated.

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

③ Multiple interfaces can be inherited, and only one class can be inherited.

④ The expressions have different meanings. An interface mainly defines a standard for unified calling methods, that is, the constraint class and the constraint class. The class is the implementation and set of methods and functions.

Similarities:

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

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

③ Interfaces and classes can contain events, indexers, methods, and attributes.

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

① Inheritance: interfaces support multi-inheritance; abstract classes cannot implement multi-inheritance.

② Concept of expression: interfaces are used for standardization, with more emphasis on contracts. abstract classes are used for commonality, and parent and child are emphasized. Abstract classes are highly aggregated for A type of things. For subclass inheriting abstract classes, abstract classes belong to the "Is A" relation, while interfaces define behavior rules, emphasize the relationship of "Can Do", so for the subclass that implements the interface, it is "behavior needs to be done according to the interface" as opposed to the interface ".

③ Method implementation: the methods in the abstract class can be provided with or without implementation. The methods (abstract rules) of interfaces cannot provide the implementation part, the modifier cannot be added to methods in the interface.

④ Subclass Rewriting: the inheritance class has different implementations for the methods involved in the two. For abstract methods defined by abstract classes, the inherited classes do not need to be overwritten. That is to say, they can be extended. For methods or attributes defined by interface classes, the inheritance class must be rewritten to provide corresponding methods and attribute implementations.

⑤ Impact of new methods: in an abstract class, if a new method is added, the inheritance class does not need to be processed. For an interface, you need to modify the inheritance class and provide a new defined method.

⑥ The interface can act on the Value Type (enumeration can implement the interface) and the reference type; the abstract class can only act on the reference type.

7. The interface cannot contain fields and implemented methods. The interface only contains methods, attributes, indexers, and event signatures. abstract classes can define fields, attributes, and methods that are implemented.

4. Differences between virtual, sealed, override, and abstract

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

② Sealed indicates that this class cannot be inherited

③ Override method of the base class

④ Abstract declares the keywords of abstract classes and abstract methods. abstract methods are implemented by sub-classes and cannot be instantiated.

5. What is the difference between override and overload?

Overload: A method overload occurs when the class contains two methods with the same name but different signatures (with the same method name and different parameter lists. Method Overloading is used to provide methods that implement the same semantics and have different functions. (Multiple methods in a class)

Rewrite: Used in class inheritance. The override subclass method can change the implementation of the parent class virtual method. (Two or more classes)

6. Differences between struct and class

① Struct is a value type, and class is a reference type
② Struct does not support constructor, destructor, and protected modification;
③ Struct is often used for data storage, and classes are mostly used for behavior;
④ Class objects need to be instantiated with the new Keyword. struct may not apply to the new Keyword;
⑤ Class can be an abstract class, and struct does not support abstraction;

7. Similarities and Differences Between out and ref

① Ref requires that parameters be explicitly initialized before use, and out should be initialized inside the method;

② Out is suitable for use where multiple retrun return values are required, while ref is used when the caller's reference is modified by the method to be called.

③ Ref indicates that input and output exist, and out indicates that only output is not performed. (ref can pass the value of the parameter to the function, but out indicates clearing the parameter, that is to say, you cannot pass a value from out. After an out value is input, the value of the parameter is null)

8. Differences between value types and reference types

① Value Type: refers to the amount of actual data. That is to say, when a value type variable is defined, C # allocates a storage area suitable for size to the variable in stack mode based on the declared type, then the read or write operations on this variable are directly performed in this memory area;

② Reference type: a variable of reference type does not store the actual data they represent, but stores the reference of 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 stack, and then the memory handle (also the first address of the memory) assign to referenced variable;

 

9. What is unpacking and packing?

Packing → converting value type to reference type, disassembling → converting reference type to value type.

10. What are the effects of packing and unpacking on performance? How can this problem be solved?

① Impact: both involve memory allocation and object creation, which have a greater impact on performance;

② Solution: use generic

11. What is delegation? Is the event delegated?

(1) delegate: similar to the function pointer in C or C ++, a method can be passed as a parameter. (a method can be substituted into another method as a parameter)

② An event is a Special Delegate, which is implemented internally Based on the delegate;

12. Can Constructor be inherited? Can be overwritten?

Constructor cannot be inherited, so it cannot be overwritten, but can be overloaded ).

13. Can I integrate the String class?

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

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

No. The method of an object can only be accessed by one thread.

15. In the most effective way, how much is the value of 2 multiplied by 8?

2 <3 (left multiplication, Right Division)

16. What is the difference between Error and Exception?

Error indicates that the restoration is not impossible, but difficult. Exception indicates an actual or implementation problem. It indicates that the program runs normally and cannot occur.

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

① TCP is a transmission control protocol that provides connection-oriented and reliable byte stream services. TCP provides time-out redial and data verification functions.

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

18. usage of the new Keyword

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

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

③ The new constraint is used to restrict the types of parameters that may be used as type parameters in a generic declaration.

19. Using Keyword usage

① Reference a namespace;

② Create an alias for the namespace or type; (using + alias = specific type that includes detailed namespace Information)

  ③ Release resources (close file streams );

20. What are the accessibility levels?

① Unlimited pubic access.

② Protected access is limited to include classes or types derived from include classes.

③ Internal access is limited to the current Assembly.

④ Protected internal access is limited to the current Assembly or type derived from the include class.

⑤ Private access is limited to the inclusion type.

21. The rules for columns are as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34 ...... calculate the number of 30th digits and use a recursive algorithm.

22. Bubble Sorting

 

All references are as follows:

Http://www.cnblogs.com/lgxlsm/p/5256482.htmlhttp://www.cnblogs.com/jx270/p/3367431.htmlhttp://www.cnblogs.com/lhws/archive/2010/09/21/1827115.htmlhttp://www.cnblogs.com/Shadowing/archive/2013/11/13/3422185.htmlhttp://www.cnblogs.com/yangzhiyu/p/3950550.htmlhttp://blog.csdn.net/wust__wangfan/article/details/17841055
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.