C # answers

Source: Internet
Author: User
C # answers to short answer questions [Reproduced]
Http://season.ouc.edu.cn By icyfire

It seems to be a question for many interview questions.

However, I am sending a reference to the exam. If you have any questions about the answers, contact iron !~

 

Answer questions
1. What are the main object-oriented ideas? Inherited polymorphism Encapsulation

Encapsulation: the data and data-based operations are encapsulated with abstract data types, and the data is protected within the abstract data type.

Inheritance: subclass has all data and operations of the parent class.

Polymorphism: the coexistence of different methods with the same name in a program.

There are two forms of polymorphism-overloading and rewriting.

 

2. What is packing and unpacking? Examples.

The boxing and unboxing mechanisms enable conversion between any value type, reference type, and object type in the C # type system. This conversion is called a binding connection. Simply put, with the concepts of packing and unpacking, values of any type can be regarded as objects. 1. Packing and conversion

Meaning: implicitly convert a value type to an object type, or convert the value type to an interface type applied to this value type, and pack a value type value, creates an object instance and copies the value to the object.

For example: int I = 10; object OBJ = I; you can also use an explicit method for packing: Object OBJ = (object) I;

2. binning and conversion

In contrast to packing, unpacking refers to explicitly converting an object type into a value type, or explicitly converting an interface type into a value type that executes this interface.

The process is divided into two steps:

First, check this object instance to see if it is a boxed value of the given value type.

Then, copy the Instance value to the value type variable. For example:

Int I = 10;

Object OBJ = I;

Int J = (INT) OBJ;

 

3. What is overload? What is the difference between override and overload?

Overload is the method inherited from the pointer pair, and its processing method is re-designed to overwrite the original Processing Method in the future.

Override is added before the method to be overwritten by the derived class, and virtual is added before the method of the base class with the same name. In this way, polymorphism can be achieved. Polymorphism refers to the coexistence of different methods with the same name in a program. There are two forms of polymorphism-overloading and rewriting.

 

4. What is the difference between the value type and the reference type? Write the sample code of C.

Variable of the value type itself contains their data, while variable of the reference type contains a reference or a handle pointing to the memory block containing the data.

Value Type variables are stored in the stack. Each program has its own stack during execution, and other programs cannot be accessed.

The reference type is stored in the heap. The address of the reference value for storing the actual data of the reference type.

There are four reference types in C #.

(Class, representative, array, interface)

 

5. How to understand delegation?

Proxy is a new type in C #. A proxy is required to pass methods as parameters to other methods.

The method uses parameters to obtain the data that is passed by the outside world and perform some operations on the data.

C # implement it through the proxy mechanism and pass a method to another method through parameters.

Proxy Step 4:

A. Generate a custom proxy class: Delegate int mydelegate ();

B. Use the new operator to instantiate the proxy class:

Mydelegate d = new mydelegate (myclass. mymethod );

C. Call the method through the Instance Object: int ret = D ();

D. In a program, the Instance Object of the application proxy calls the method it points to, just like calling a method. Delegate int D (int I );

 

6. What are the similarities and differences between interfaces and classes in C.

What is a class? Classes can be understood as a set of functions. classes can also be seen as a set of functions or methods. The concept of interfaces: What is an interface? Interfaces can be understood as Class rules, class constraints, and even project constraints. template defines the methods that must be implemented by the object, so that these methods can be referenced as interface instances. The interface cannot be instantiated. The interface is responsible for defining functions. The project uses interfaces to define the concepts of classes, Operation classes, and abstract classes! The class is responsible for the specific implementation of the function! There is also an abstract class definition in the class. The difference between the abstract class and the interface is that the abstract class is an incomplete class, which contains abstract methods and attributes, you can also have specific methods and attributes that require further specialization. But the interface is a behavior specification, and everything in it is abstract! A class can only inherit one base class, that is, the parent class, but multiple interfaces can be implemented.

 

7. What classes do I need to read and write databases in. Net?

Connection dataadapter dataset command datareader

 

8. How to understand the garbage collection mechanism in. net.

If the memory is not enough, the garbage collector takes all the objects as invalid objects (recycled objects), and then takes the global variables, static, and local variables in the active state, and put the object pointed to by the current CG pointer into a table. then

The system searches for objects in the new list and adds them to the list. Other objects not included in the list will be recycled.

For unmanaged objects, remember to release resources.

 

9. What is the error handling mechanism of. Net?

Error handling sequence: Finally first, catch second, and finally try code .. cancel this operation. returns exception information in catch. of course, you can also customize your own error handling mechanism... if your exception handling contains finally blocks. then this finally will always be executed regardless of whether an exception occurs...

 

10. What is the significance of the using and new keywords in C?

Using is used to create an alias for a namespace or reference other namespaces in the system.

New is used to create instances or override methods.

 

11. What are the differences between classes and structures?

1. Value Type and reference type

Structure is value type: value type is allocated on the stack.

Class is a reference type: the reference type is allocated on the stack.

2. Inheritance

Structure: it cannot be inherited from another structure or class. Although the sealed statement is not clear, the structure can be implicitly sealed.

Class: fully scalable. Unless sealed is explicitly declared, the class can inherit from other classes and interfaces and inherit from itself.

Note: although the structure cannot be inherited, the structure can inherit interfaces. methods are the same as class inheritance interfaces.

3. Differences in the internal structure:

Structure:

No default constructor exists. You can add constructor.

No destructor

No abstract and sealed (because it cannot be inherited)

The protected modifier cannot exist.

New Initialization is not required.

It is incorrect to initialize the instance field in the structure.

Class:

Default constructor available

Destructor

Abstract and sealed can be used.

There is a protected Modifier

New must be used for initialization.

 

12. What is CLR?

Common Language Runtime (CLR) provides a reliable and complete multi-language runtime environment. CLR is a software engine used to load applications, check errors, perform security license authentication, execute, and clear memory. It is a type of pure dynamic runtime. Its main component is virtual execution enging, which can break the language and platform restrictions.

 

13. What are the advantages of C? List at least 4 points

 

1. the pointer in C # has disappeared. Restrictions on the use of the original pointer are allowed.

2. Based on the. NET platform, it inherits the features of Automatic Memory Management and garbage collection.

3. C # has built-in support to convert any component into a web service. Any application running on any platform can use this service over the Internet.

4. Object-oriented

14. What are the three principles of object-oriented programming? Describe them separately.

Inheritance: each class supports a single inheritance, but the class can implement multiple interfaces. All classes are inherited from a common base class.

Encapsulation and visibility: Both determine whether class members are visible. Besides the internal access modifier of C #, the visibility mechanisms of the two are very similar.

Polymorphism: both Java and C # support some forms of polymorphism, And the implementation methods are very similar.

 

15. C # What are the five types of accessibility?

Public: Members can access any code.

Protected: A member can only be accessed from a derived class.

Internal: members can only access from within the same assembly.

Protected internal: A member can only be accessed from a derived class in the same assembly.

PRIVATE: members can only be accessed within the current class.

 

16. C # compile the code into an intermediate language before execution. What are the main features of the intermediate language?

 

● Object-oriented and user interfaces

● The huge difference between the value type and the reference type

● Strong data types

● Use exceptions to handle errors

● Attribute)

 

17. C # What types of reference are there?

(Class, representative, array, interface)

18. What are the three possible relationships between objects?

Aggregation: A (more complex) object is composed of several (relatively simple) other objects, called aggregation.

The static link between objects (that is, the link embodied by object attributes ).

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.