Examples of some interview questions in C # tutorials

Source: Internet
Author: User
Tags aliases
Recently a net development friend left, want me to find some about net related interview questions, ready to hug Buddha feet, to meet new challenges.

I quickly find the previous search of the various treasure, test questions, today comb the basic knowledge of the net point.

1, object-oriented language of the three major features: encapsulation, inheritance, polymorphism;

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

Different points:

The ① interface cannot be instantiated directly.

The ② interface contains only the declaration of a method or property and does not contain the implementation of the method.

The ③ interface can inherit multiple, and the class can only be single-inherited.

④ the meaning of the expression, the interface mainly defines a specification, the unified calling method, that is, the specification class, the constraint class, the class is the method function realization and the collection

Same point:

① interfaces, classes, and structs can inherit from multiple interfaces.

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

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

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

① Inheritance: The interface supports multiple inheritance, and abstract classes cannot implement multiple inheritance.

The concept of ② expression: interfaces are used for specification, more emphasis on contracts, abstract classes for commonalities, and parent-child emphasis. Abstract class is a kind of high aggregation of things, then for the subclass of the inheritance abstract class, for the abstract class, belongs to the "is A" relationship, and the interface is to define the behavior specification, emphasizing the "Can do" relationship, so for the implementation of the interface subclass, relative to the interface, is "behavior needs to follow the interface to complete."

③ method Implementation: The method in the abstract class, that can give the implementation of the part, can not be given, but the interface method (abstract rules) can not give the implementation of the part, the interface method can not add modifiers.

④ Subclass rewrite: Inheriting classes are different implementations of the methods involved. The abstract method that the inheriting class defines for the abstract class can be used without rewriting, that is to say, the method of the abstract class can be used, and the method or property defined by the interface class must be overridden in the inheriting class, giving the corresponding method and property implementation.

⑤ the impact of new methods: in an abstract class, a new method can be used without any processing in the inheriting class, and for an interface it is necessary to modify the inheriting class to provide a new defined method.

The ⑥ interface can be used for value types (enumerations can implement interfaces) and reference types, and abstract classes can only be used for reference types.

The ⑦ interface cannot contain fields and implemented methods, interfaces contain only methods, properties, indexers, and signatures of events; Abstract classes can define fields, properties, and methods that contain implementations.

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

①virtual declares the keyword of the virtual method, which indicates that the method can be overridden

②sealed indicates that the class cannot be inherited

③override methods for overriding base classes

④abstract affirms the keywords of abstract classes and abstract methods, the abstract methods do not provide implementations, subclasses implement, abstract classes are not instantiated.

5. What is the difference between overloading (override) and rewriting (overload)

Overloading: A method overload occurs when a class contains two methods with the same name but different signatures (the same method name, not the same argument list). Method overloads are used to provide methods that are semantically identical and functionally different. (In a class, multiple methods)

Rewrite: Used in the inheritance of the class, the implementation of the virtual method of the parent class can be changed by overriding the subclass method. (two classes or more)

6, the difference between the structure and the class

① struct is a value type, class is a reference type
The ② structure does not support the non-tragic constructor, does not support the destructor, and cannot have protected modification;
③ structures are often used for data storage, class classes are used for behavior;
The ④ class needs to instantiate the object with the New keyword, and the struct may not apply the new keyword;
⑤ classes can be abstract classes, structs do not support abstraction;

7. Similarities and differences of out and ref

①ref requires that parameters be explicitly initialized before use, out is initialized inside the method;

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

③ref is there in, out is only out of the way, (ref can pass the value of the parameter into the function, but out is to empty the parameters, that is, you can not transfer a value from the out, after out, the value of the parameter is empty)

8. Differences between value types and reference types

① value type: is a quantity that contains the actual data. That is, when a variable of a value type is defined, C # allocates a chunk of the appropriate storage area to the variable according to the type it declares, and then the read or write operation of the variable is performed directly in the memory area;

② reference type: A variable of a reference type does not store the actual data that they represent, but instead 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 assign the memory handle (also the first address of the memory) to the reference variable;

9. What is unpacking and packing

Boxing → value types are converted to reference types, and unboxing → reference types are converted to value types.

10. What are the performance effects of packing and unpacking? How to solve it?

① Impact: All involved in the allocation of memory and the creation of objects, have a greater performance impact;

② Resolution: Using generics

11. What is a delegate? Event is not a delegate?

① delegate: Similar to a function pointer in C or C + +, allows the method to be passed as a parameter; (You can substitute one method as a parameter into another)

The ② event is a special delegate, and the internal event is implemented based on the delegate;

12. Can the constructor constructor be inherited? Is it possible to override?

Constructor can not be inherited and therefore cannot be overridden (overriding), but can be overloaded (overloading).

13. Can I integrate the String class?

The string class is the final class, so you cannot inherit the string class.

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

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

15, the most effective way to calculate 2 times 8 is equal to a few?

2<<3 (left multiply, right divide)

16, error and exception there is a difference?

Error indicates that recovery is not impossible, but difficult, exception represents an actual or implementation problem, which indicates that the program does not work properly can not occur.

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

①TCP is a Transmission Control protocol that provides connection-oriented, reliable, byte-stream service, TCP provides timeout redial, and verifies data functionality.

②UDP is a User Datagram protocol that is a simple datagram-oriented transport protocol and is unreliable for connection.

18. Use of the New keyword

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

The ②new modifier is used to hide an inherited member from a base class member.

The ③new constraint is used to constrain the type of a parameter that may be used as a type parameter in a generic declaration.

19. Usage of using keyword

① reference namespace;

② creating aliases for namespaces or types; (using + aliases = Specific types that include detailed namespace information)

  ③ Releasing resources (close file stream);

20. What kinds of accessibility levels do you have?

①pubic access is not restricted.

②protected access is limited to types that contain or derive 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 of a column are as follows: 1, 1, 2, 3, 5, 8, 13, 21, 34 ... The 30th digit is the number, which is realized by recursive algorithm.

22. Bubble sort

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.