. NET Foundation questions and Answers II

Source: Internet
Author: User
Tags soap

1. Override and overload

Overloading should be called overload, override called Override, and Overloading A method occurs in the same class! Overriding is to override a method in a subclass in a parent class.

1.override:Parent class:Public Virtual String ToString () {return "a";}
Sub-class:Public override String ToString () {return ' B ';}
2.overload:can be in the same class or in a parent-child relationship class.
public string ToString () {return "a";}
public string ToString (int id) {return ID. ToString ();}
Rewrite(Override)is the virtual method used to override the base class,This provides a new method in the derived class;

Overloading (overload) provides a mechanism by which the same function names are differentiated by different return value types and parameter-to-table .

2. The difference between managed and unmanaged

Managed code is code compiled by the Visual Basic. NET and C # compilers. The compiler compiles the code into intermediate language (IL)insteadof the machine code that runs directly on your computer. The intermediate language is encapsulated in a file called an assembly (assembly) , which contains descriptions of the classes, methods, and properties that you create, such as security requirements ) for all of the meta data. You can copy this assembly to another server to deploy it. Typically, the action of this copy is the only action in the deployment process.

Managed code in the common language runtime(CLR)Run in. This runtime provides a variety of services to your running code, and in general, he loads and validates the assembly to ensure the correctness of the intermediate language. When some methods are called, the runtime compiles the specific method into a machine code that is suitable for the local computer to run, and then caches the compiled machine code for the next call(This is the instant compile). As the assembly runs, the runtime continuously provides services such as security, memory management, thread management, and so on. This program is"managed"in the run-the-Library. Visual Basic. NETand theC #only managed code can be generated. If you write a program in such a language, the resulting code is managed code. If you like,Visual C + +. NETmanaged code can be generated. When you create a project, select the name to. Managedthe project type that begins. For example. Managed C + + application.

The

Unmanaged code compiles directly to the machine code of the target computer, which can only be run on the computer that compiles them, or on a computer that has the same processor or almost the same processor. Unmanaged code cannot enjoy some of the services provided by the runtime, such as security and memory management. If unmanaged code requires services such as memory management, you must explicitly invoke the interface of the operating system, which typically calls windows sdk api to achieve. In recent cases, the unmanaged program passes the com interface to obtain operating system services. With visual studio visual c++ You can create an unmanaged program. When you create a project and select the name to mfc , Span style= "Font-family:verdana;" >atl win32 start with the project type, then this project produces an unmanaged program.

In summary, unmanaged code is code that runs outside the common language runtime Environment (CLR) and is executed directly by the operating system. Unmanaged code must provide its own garbage collection, type checking, security support, and other services, unlike managed code, which obtains these services from the common language runtime.

3. The difference between Equals and the use of "= ="

Because a value type is a stack that is stored in memory (hereafter referred to as a stack), a variable of the reference type is simply the address of the reference type variable stored in the stack, and itself stored in the heap.

The = = Operation compares the values of two variables for equality, and for a reference variable represents whether the two variables are stored in the same address in the heap, that is, whether the contents of the stack are the same.

Whether the two variables represented by the equals operation are references to the same object, that is, whether the contents of the heap are the same.

  

4. Expansion method

The extension method allows classes to be changed, but the source code for the class is not required.

The extension method is a static method, which is part of the class, but is not actually placed in the source code of the class.

Suppose the money class needs a method addtoamount (decimal amounttoadd). However, for some reason, the original source code of the assembly cannot be modified directly. All the work you have to do at this point is to create a static class and add the method addtoamount as a static method. The corresponding code is as follows :

Note the parameters of the addtoamount () method, for the extension method, the first parameter is the type to expand, which is placed after the This keyword. This tells the compiler that this method is part of the money class.

5. What is webservice and what is the understanding of it?

WebService is a technology developed by Microsoft for Service-oriented (SOA) programming, which uses the WSDL description language to declare an interface to a service that can be referenced, and uses the SOAP simple Object Access protocol to transmit data in the same way, such as method parameters and return values. The objects transmitted in SOAP are serialized XML-formatted data, which can penetrate firewalls and carry out the transfer of objects between different applications.

6. What are the similarities and differences between UDP link and TCP link?

The UDP protocol does not necessarily provide reliable data transfer, which means that the protocol does not guarantee the accuracy of the information to the destination. However, if the goal of your program is to transfer as much information as possible as soon as possible using UDP to achieve, such as QQ, YY voice and other chat programs.
TCP/IP provides reliable data transfer and maintains a virtual connection between devices or services that communicate with each other. Responsible for data recovery when packets are received unordered, lost, or destroyed during delivery.

7. The difference between private, protected, public, and internal modifiers in C #

Private access is restricted to members of this class, and subclasses and instances are inaccessible.

Protected Protected Access is restricted to this class and subclass access, and instances cannot be accessed.

Public access is not subject to any restrictions.

Internal internal access, limited to access within this project, other inaccessible.

8, bubble sort, fast row and other basic data structure

1, bubble sort basic idea: the N records as a vertical arrangement, each order in accordance with the bottom-up on each pair of adjacent records to compare, if the order does not meet the requirements of the exchange. Each trip to the end of the sorting can make the list of keywords the smallest record like bubbles up to the corresponding position at the top of the table, the entire sorting process is n-1, in turn, the keyword is the smallest, the second small, the third small ... The first, second, and third of each record of the table. Position.

Example code:

for (int i = 0; i < a.length; i++)

{

for (int j = a.length-1;j>i;j--)

{

if (A[j] < a[j-1])

{

int temp = A[j];

A[J] = a[j-1];

A[J-1] = temp;

flag = 1;

}

}

}

2. Quick sort: The idea of quick sorting is the thought of division and treatment.

A quick sort is to find an element as a datum and then partition the array so that the values of the elements on the left of the datum are not greater than the datum values, and the values to the right of the datum are not less than the datum values.

Instance code:

int quicksort (vector<int> &v, int left, int. right) {
if (left < right) {
int key = V[left];
int low = left;
int high = right;
while (Low < high) {
while (Low < high && V[high] > key) {
high--;
}
V[low] = V[high];
while (Low < high && V[low] < key) {
low++;
}
V[high] = V[low];
}
V[low] = key;
Quicksort (v,left,low-1);
Quicksort (V,low+1,right);
}
}

9. Disassembly and packing, and performance loss of unpacking and crating

Boxing is the conversion of a value type into a reference type, and unpacking is the conversion of a reference type into a value type.

During the boxing process, the value type is copied and assigned to the managed heap and converted to the corresponding reference type, which can result in a loss of performance.

During the unboxing process, the reference types in the managed heap are copied to the stack and converted to the corresponding types, which can also result in a loss of performance.

. NET Foundation questions and Answers II

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.