. NET basic interview questions and. net questions

Source: Internet
Author: User

. NET basic interview questions and. net questions

I graduated this year and have some temporary preparations before the interview during my job search this semester.

The following answers to the interview questions shared by Lao Zhao refer to the books and video tutorials on hand, as well as the online materials. I hope this will help you, if this is not the case or is not the case, I hope you can point it out.

1. What is. NET? What is CLI? What is CLR? What is IL?

 

(1). net is an integrated hosting environment for code compilation and execution. In other words, it manages all aspects of application programs, including the compilation of the first run, and allocates memory for the program
Store Data and commands, grant or deny permissions to the application, and start the execution of the management application. The remaining memory is allocated. Because all. net Applications
They are all executed on the. net framework. Therefore, developers only need to consider dealing with the. net framework, instead of having to relate to the implementation of the underlying operating system.
Including CLR and BCL


(2) CLI (common language infrastructure) Public language infrastructure, an international standard, does not specify how the standard is implemented. Instead, it describes
What behavior should the CLI platform perform when it complies with the standards. Including: Runtime (CLR), common intermediate language (CER), Common Type System (CTS ),
Common Language Specification (CLS), Metadata (Metadata), framework)


(3) CLR: loads and runs the program IL: intermediate language during the common language runtime. The C # compiler converts the C # code into IL, which can be understood during the runtime, and compiled into machine code

2. What is JIT and how does it work? What is GC? How does GC work?

 

JIT: Just in time, C # Or VB. NET code is first compiled into IL and stored locally. When you want to run the code, CLR will perform the second compilation on IL and convert it to machine code for running. Benefits: portability, and IL will be checked for type security when loaded into the memory, which achieves better security and reliability.

GC: garbage collection (garbage collection) is a process that automatically allocates and recycles Memory Based on program requirements. The garbage collector processes referenced objects and only recycles the memory on the stack. This means that if you maintain a reference to an object, it will prevent GC from reusing the memory used by the object. In. NET, the garbage collector uses the mark-and-compact algorithm. At the beginning of a garbage collection cycle, it needs to identify all objects and references. Based on this reference, it can traverse a tree structure identified by each root reference, recursively determine all referenced objects. In this way, the garbage collector can recognize all reachable objects. During garbage collection, GC does not enumerate all inaccessible objects. On the contrary, decompress all adjacent reachable objects for garbage collection. Inaccessible objects will be overwritten. The purpose of garbage collection is to improve the memory usage. It is not used to clear file handles, and to connect strings, ports, or other limited resources to the database (the finalizer cannot be called explicitly, no parameters can be passed, that is, they cannot be overloaded. Only the garbage collector can call the Terminator and use the Using statement for deterministic termination.

 3. What is the difference between class and struct? Do they affect performance?

1. Value Type and reference type

Structure is value type: value type is allocated to the stack. All base types are structure types. For example, int corresponds to the System. int32 structure. More value types can be created by using the structure.
Class is a reference type: the allocation of address stack on the stack is more efficient than that on the stack. However, the stack resources are limited and it is not suitable for processing large logical and complex objects. Therefore, structure processing is a small object to be treated as a base type, while classes can create a new structure for assigning values between structures because the structure is a value type, while classes are reference types, the assignment between classes is just a copy reference.
Note: 1. Although the structure is different from the class type, their base types are all objects, and all types of base types in c # Are objects.
2. although the New operator is used for structure initialization, the structure object is still allocated on the stack instead of the stack. If the new operator is not used, before all fields are initialized, the field remains unassigned and the object is unavailable.

2. Inheritance

Structure: it cannot be inherited from another structure or class. Although the structure is not explicitly declared using sealed, the structure is implicit sealed.
Class: fully scalable. The class can inherit other classes and interfaces unless the declared sealed is displayed. Note: although the structure cannot be inherited, the structure can inherit interfaces, the method is the same as the class inheritance interface.

3. Internal Structure:
Structure: no default constructor, but you can add constructor. No destructor, no abstract and sealed (because it cannot be inherited) the protected modifier is not available. It is incorrect to initialize the instance field in the structure without using new initialization.
Class: default constructor and destructor. abstract and sealed can be used to have the protected modifier.
New must be used for initialization.

4. What are classes (structures) in. net bcl and why are they not structures (classes )?

Structure: System. Boolean Byte Char Decimal Double Int32
The stack space is limited. For a large number of logical objects, the creation class is better than the creation structure. In most cases, this type is only the best choice for the structure when it comes to some data.
Class: String Object Delegate interface and so on. It contains a large number of logical objects and represents abstraction.

 5. How do you select a class or structure for custom types?

1) The stack space is limited. For a large number of logical objects, creating classes is better than creating structures.
2) The structure represents lightweight objects such as dots, rectangles, and colors. For example, if an array containing 1000 vertex objects is declared, additional memory will be allocated to each referenced object. In this case, the structure cost is low.
3). Classes are the best choice for presentation of abstract and multi-level object layers.
4). In most cases, this type is the best choice for structure when it is only some data.

6. What is heap and stack when the. NET program is running? 

The stack usually stores the steps for executing code, while the stack stores objects and data. We can think of a stack as a box stacked together. When we use it, each time we take a box from the top. The same is true for the stack. When a method (or type) is called, it is removed from the top of the stack (called a Frame, annotation: Call Frame), followed by the next one. The heap is not a repository. It stores the various objects we use and other information. Different from the stack, they are not cleared immediately after being called.
Stack memory does not need to be managed or managed by GC. When the top element of the stack is used up, it is immediately released. While the heap requires GC (Garbage collection: Garbage Collector) cleaning.

7. Under what circumstances will data be allocated on the heap (stack? Are there any performance differences between them? Can "structure" objects be allocated to the stack? Under what circumstances will happen, do you need to pay attention to it?

1) The value type is generally allocated to the pair, and the reference type is allocated to the heap. Stack efficiency is higher than stack efficiency.
2) possibly, when a structure type is defined in the class, the structure is allocated to the stack.

8. What is the role of generics? What are its advantages? Does it affect performance? What is its behavior during execution?

Purpose: To promote code reuse, especially algorithm Reuse
Advantages: (1) reusability (2) type security. In parameterized classes, only the desired data type can be used. (3) performance: avoid the forced conversion from the Object and the packing of the value type (4) Reduce the memory consumption: Avoid packing and do not need to consume the memory on the heap.
Behavior during execution: generics are also objects, and the "type parameters" of generic classes are changed to metadata. CLR constructs classes that utilize them as needed. A generic class is no different from a common class after compilation. The compilation result only includes metadata and the pencil. Value-type-based generic instantiation: CLR will place the specified type parameters in a proper location in the pencil to create a specific generic type. Therefore, CLR creates a specific generic type for no new parameter values.
Instantiation based on the reference type: CLR creates a specific generic type. Later, every time a constructed type is instantiated with a reference type parameter, and the type parameter is referenced and replaced with an Object in the pencil, the CLR will reuse the previously generated generic version.

 9. What generic types does. net bcl have? Examples illustrate the generic types that you define in normal programming.

List <T>: access a List of strong types through Indexes
Dictionary <T>: indicates the set of key-value pairs.
Queue <T>: Queue Stack <T>: Stack
The shopping cart is simulated using Dictionary. When the OA obtains the employee list and other data, the returned value is generic.

 10. What is the role of an exception ?. What are common exceptions in net bcl? In code, How do you capture/handle exceptions? In catch (ex), what is the difference between throw and throw ex? How do you design an exception structure? Under what circumstances will you throw an exception?

(1) C # The exception handling function of the language helps you handle any exceptions or exceptions during the running of the program.
(2) throw retains stack information. Throw ex won't. Of course, if you set innerException before throwing a new exception, you can access the original stack through the innerException stack.
(3) If an exception is detected, try catch finally to catch the exception. If it is unexpected, an error will be reported directly without processing (insufficient memory, deleting files), making it easier to find the catch Block from the most specific to the regular arrangement.

11. What is the difference between List <T> and T []? How do you choose? What is Dictionary <TKey, TValue> ?. Which of the following commonly used containers does net bcl support? How are they implemented (which data structure )? Which scenarios are applicable?


1. List <T> the generic version of arrylist. The size is variable. T [] is inherited from Array and the size is fixed. If the size does not change, select T []. Generally, select List <T>
2. Dictionary is a generic version of hashtable used to store key-value pairs, such as sortlist and stack.

12 what is the difference between an abstract class and an interface? What do you need to pay attention to when using it?


How can I choose whether to define a "completely abstract" abstract class or an interface? What is "explicit implementation" of interfaces "? Why is it important?
Similarities: neither of them can be directly instantiated, and their abstract methods can be implemented through inheritance.
Differences:
(1) interfaces support multi-inheritance; abstract classes cannot implement multi-inheritance.
(2) interfaces can only define behaviors. abstract classes can either define behaviors or provide implementations.
(3) An abstract class can contain virtual members of the implementation. Therefore, it can provide a default implementation for the members of the derived class. All members of the interface automatically become virtual members and cannot contain any implementations.

13. Is the string a reference type or a structure type? Reference Type


Is it more special than a common reference type? Immutable
What should I pay attention to when using strings? Why is StringBuilder more efficient?
When splicing two strings, the system first writes the two strings to the memory, then deletes the original String object, creates a String object, and reads the data in the memory and assigns it. This process takes a lot of time. The StringBuilder class under the System. Text namespace is not like this. It provides the Append method, which can be used to modify strings in the existing object, which is simple and direct.
When connecting multiple strings, is it more efficient than directly adding strings at any time?
Not necessarily, the effect is the same for less than 1000 characters. When the value reaches 10000, The StringBuilder class efficiency will be significantly improved.
How to efficiently copy arrays? What is the difference between "two-dimensional array" and "array?
Array replication method: for CopyTo () Static CopyTo () Clone

14. What are the methods and scenarios of metaprogramming and. NET? What is reflection? Can I introduce some common reflection scenarios? Some people say that the reflection performance is poor. What do you think of this problem? Is there any way to improve the reflection performance?


When learning to do OA, dynamic loading of different DataProvider (Oracle and Sqlserver), convenient, can be replaced at any time without re-compiling the program

15. What is delegation? What is an anonymous method? In C #3.0, what is a Lambda expression? What is the extension method? What is LINQ? What are the important features of C #3.0 and their advantages? Which libraries in BCL are related to these features? What do you usually use most?


A delegate can substitute a method as a parameter into another method.
The delegate can be understood as a pointer to a function.
Anonymous Method: A delegate instance without actual method declaration. Or, their definitions are directly embedded in the code.
Lambda expressions: An anonymous function syntax that is more concise than the anonymous method
The delegate and event are not comparable, because the delegate is a type, and the event is an object. The following describes the delegate objects (events implemented using the delegate method) and (implemented using the standard event method) event differences. Internal events are implemented by delegation. For an event, you can only register yourself + = or deregister yourself-=. other registrants cannot be deregistered, or the event cannot be triggered, therefore, if Delegate is used, the above control cannot be implemented, so the event syntax is born. The event is used to caster the delegated instance, similar to a custom class castrated List. Events can only be added or removed, but cannot be assigned values. The event can only be + =,-=, and cannot be =. An event is a private delegate, add, and remove methods.

16. What technical books, websites, communities and projects do you read outside of work?


What other. NET technologies do you still use? Can you compare them with some targeted ones in. NET or. NET?
C # Essence, SQL Server2008 practice, data structure, ASP. NET secrets, Javascript in a simple way

17. Differences between website and webapplication


1) After modifying the website, you do not need to restart it to see the effect.
2) No namespace is specified for the website. The webapplication has a namespace.
3) website is designed to be compatible with the developer habits transferred by asp.
4) there is no technical difference and debugging habits are different
5) The website is compiled into a dll, And the webapplication generates a dll.
6) It is not conducive to project development. For example, it is difficult to detect code errors.

18. To set the name for the form submitted to the server, you can leave the id Unspecified. The server only uses the name, and the Dom uses the id.

19. To identify whether to enter the page for the first time or click Submit to enter the page again, form has a hidden field:


<Input type = "hidden" name = "ispostback" value = "true"/>. If ispostback = true is read from the Request, click Submit to go to ashx, otherwise, it is the first time you enter ashx.

20. Http is a request-response model. The server does not read the web page of the browser and can obtain the data submitted by the web page.

21. Comparison between get and post submission


Get: Pass the form value through URL (default ),?... &, Low security, small data transmission.
Post: The passed value is hidden in the http message and cannot be seen in the URL. A prompt dialog box is displayed on the refresh page. If

22. implement self-incrementing text in p, because the server does not remember the value that was last sent to the browser, and will re-submit the last value unlike input, therefore, the browser needs to use a hidden field to save the previous value.

23. ViewState implementation principle


Non-form elements cannot pass client element values to the server. Even form elements can only pass value values. Other attribute values, such as the background color and size, cannot be passed, therefore, these values must exist in hidden fields. The Viewstate is page-related. The viewstate of a page is different from that of a page, and does not affect each other. ViewState can be useful for pages that require PostBack processing. For pages such as news presentation, ViewState can be disabled to improve performance without interaction. If no ViewState exists, the page cannot contain the form of runat = server.

 
24. Cookie


The form is page-related. Only the data server submitted by the browser can obtain the form. The Cookie is site-related. In addition to sending form data each time a request is sent to the server, it also submits all site-related cookies to the server, which is mandatory.
Disadvantage: too much information cannot be stored, resulting in poor security
Optimization for the Internet: The image server and the main site domain name are different

25. http request, css, js, image, and individual request. 200 indicates that the request is processed successfully, 301 redirection, and 400 Error requests.

307 temporary redirection, 404 page not found, 403 forbidden, 401 unauthenticated, 503 server internal error, too many visitors.

26./: root directory of the website,.../directory at the upper level,./current directory ,~ /Application root directory

27. database query performance optimization

 

1) only the required columns are returned in the select statement.
2) Reduce the number of columns while reducing the number of rows. Use the where clause
3) Use order by only when necessary
4) avoid implicit data type conversion in the from, where, and having clauses.

Common sorting algorithms:

Using System; using System. collections. generic; using System. linq; using System. text; namespace Sort {public class Sort {// <summary> // insert sorting -- stable sorting /// </summary> /// <param name = "list"> </param> public static void InsertSort (List <int> list) {int j, tmp; for (int I = 1; I <list. count; I ++) {j = I; tmp = list [I]; while (j> 0 & tmp <= list [j-1]) {list [j] = list [j-1]; j --;} list [j] = tmp ;}/// <sum Mary> // sort by hill /// </summary> /// <param name = "list"> </param> public static void ShellSort (List <int> list) {int j, tmp; int h = 3; while (h> 0) {for (int I = h; I <list. count; I ++) {tmp = list [I]; j = I; while (j> h-1) & tmp <list [j-h]) {list [j] = list [j-h]; j-= h;} list [j] = tmp;} h = (h-1) % 3 ;}} /// <summary> /// bubble sort -- stable sort /// </summary> /// <param name = "list"> </param> public stati C void BubbleSort (List <int> list) {if (list = null | list. count <1) {return;} int tmp; for (int I = 0; I <list. count-1; ++ I) {bool flag = false; for (int j = list. count-1; j> I + 1; j --) {if (list [j]> list [j + 1]) {tmp = list [j]; list [j] = list [j + 1]; list [j + 1] = tmp; flag = true;} if (flag = false) {return ;}}}} /// <summary> /// select sort -- select sort directly /// </summary> /// <param name = "list"> </param> publ Ic static void SelectSort (List <int> list) {int min, tmp; for (int I = 0; I <list. count; I ++) {min = I; for (int j = I + 1; j <list. count; j ++) {if (list [j] <list [min]) {min = j ;}} if (I! = Min) {tmp = list [I]; list [I] = list [min]; list [min] = tmp ;}}} /// <summary> /// heap sorting /// </summary> /// <param name = "list"> </param> public static void HeapSort (List <int> list) {int n = list. count; for (int I = n/2-1; I> = 0; I --) {Sift (list, I, n-1 );} for (int I = n-1; I> = 1; I --) {int tmp = list [0]; // retrieve the heap top element list [0] = list [I]; // move the last element in the heap to the top position list [I] = tmp; // at this time, list [I] is no longer in the heap and is used to store the sorted element Sift (l Ist, 0, I-1); // reset heap} private static void Sift (List <int> list, int low, int high) // heap creation process {// I is the index number of the root node of the subtree to be adjusted, and j is the left child of this node int I = low, j = 2 * I + 1; int tmp = list [I]; // record the value of the parent node while (j <= high) {// If the left child is less than the right child, the child node to be switched is directed to the right child if (j 

Collected from: Gabriel Zhang


Net interview questions

A delegate is a class that can call one or more methods with specific signatures. The delegate parameter can be of the basic data type or. NET type, and can be passed by value or by reference. After introducing the delegation knowledge, this article discusses the topics related to the event .. . NET Framework events are based on multicast delegation .. The event mechanism in the. NET Framework consists of two parts: the event source and the event receiver. The event source is linked to the event receiver by using the event subscription mechanism .. NET Framework uses the keyword _ event to declare events. A thread is the unit of CPU time slice allocation. Different threads can have different priorities. Each process has at least one main thread. In the. NET Framework, the most basic execution unit is a thread. The managed code is executed starting with a single thread, but an additional thread can be generated during the execution to help complete the specified task. Threads are divided into foreground threads (the current process can exit only after all foreground threads exit) and background threads (the process can exit at any time without waiting for the background thread to exit ). When writing an application, programmers often need to store some data of the program in the memory, and then write it into a file or transmit it to another computer on the network for communication. This process of converting program data into a stored and transmitted format is called "Serialization", and its inverse process can be called "Deserialization ).
 
Net classic interview question what is the answer to the last few questions?

1. The function is to instantiate an array of T type with a length of size and assign a value to each element.

SomeMethod (1, 20 );
If the call is faulty, change it
SomeMethod <int> (1, 20 );

I don't want to watch it, but my eyes hurt. You have to rest.

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.