. NET Foundation question finishing

Source: Internet
Author: User
Tags modifiers try catch

Graduation this year, the semester to find a job in the pre-interview to do some temporary preparation

The following about Lao Zhao shared the face of the question answer reference to the book and video tutorials at hand, as well as the information on the Internet, is now sorted out to help you, wrong or poor place to point out that I am good to correct.

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

(1). NET integrated hosting environment for code compilation and execution, in other words, it manages all aspects of the application run, including the first run compilation, allocating memory to the program
Stores data and directives, grants or denies the appropriate permissions to the application, and initiates the execution of the management application, allocating the remaining memory. Because all. NET applications
are performed on the. NET Framework, so developers only need to consider working with the. NET Framework, without having to do with the implementation above the underlying operating system
Include CLR and BCL


(2). The CLI (Common Language Infrastructure) common language Infrastructure, an international standard, does not specify how the standards are implemented. Instead, it describes a
What behavior the CLI platform should have if it complies with the standards. Includes: Runtime (CLR), Common Intermediate language (CIL), Public type System (CTS),
Common Language Specification (CLS), metadata (Metadata), Frameworks (framework)


(3) CLR: The common language runtime, responsible for loading and running program IL: intermediate language, C # compiler converts C # code to IL, Runtime understands IL, and compiles to machine code

What is 2.JIT and how does it work? What is a GC and briefly describe how the GC works?

Jit:just in time,c# or vb.net code is first compiled to IL stored locally, and when the code is run, the CLR is converted to machine code to run the second compilation of the IL. Benefits: portability, and IL is subject to type-safety checks when loaded into memory, which enables better security and reliability.

GC: Garbage collection (garbage collection) is the process of automatically allocating and reclaiming memory according to the needs of the program. The garbage collector handles reference objects and reclaims only the memory on the heap. This means that if a reference to an object is maintained, it prevents the 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 identifies all and references to the object, which, depending on the reference, iterates through a tree structure identified by each root reference and recursively determines the object to which all references are directed. In this way, the garbage collector can identify all reachable objects, and when performing a collection, the GC does not enumerate all objects that are not accessible, instead, it performs a garbage collection by compressing all adjacent reachable objects. Objects that are not accessible are overwritten. The purpose of garbage collection is to improve the utilization of memory, it is not used to clean up the file handle, and the database connection string, port or other limited resources (terminal finalizer, cannot be displayed call, cannot pass any parameters, that is, can not be overloaded, only the garbage collector can call the terminal, Deterministic finalization using a using statement

3. What is the difference between classes (class) and struct (struct)? Do they have an impact on performance?

1. Value types and reference types

Structs are value types: value types assign addresses on the stack, all base types are struct types, for example: int corresponds to the SYSTEM.INT32 structure, and more value types can be created by using structs
A class is a reference type: a reference type that allocates an address stack on a heap is more efficient than a heap, but the stack has limited resources and is not suitable for dealing with large logical complex objects. So structure processing is a small object treated as a base type, whereas a class handles a business logic because structs are value types, assignments between structs can create new structures, and classes are reference types, and assignments between classes are just copy references
Note: 1. Although structs are different from classes, their base types are objects (object), and the base types of all types in C # are
2. Although the initialization of a struct also uses the new operator, the structure object is still allocated on the stack instead of on the heap, and if you do not use new, the field remains unassigned until all fields are initialized, and the object is not available

2. Inheritance of

Structure: Can not inherit from another structure or class, itself can not be inherited, although the structure is not explicitly declared with sealed, but the structure is implicit sealed.
Class: Fully extensible, unless the declared sealed is displayed otherwise the class can inherit other classes and interfaces, and itself can be inherited note: Although structs cannot be inherited, structs inherit interfaces, and methods and classes inherit interfaces.

3. Internal structure:
struct: There is no default constructor, but you can add constructors without destructors without abstract and sealed (because they cannot be inherited) cannot have protected modifiers can not initialize instance fields in struct without using new initialization is an error
Class: There are default constructors that have destructors that can use abstract and sealed with protected modifiers
You must use new to initialize the

4..NET What are classes (structs) in the BCL, and why are they not structs (classes)?

Structure: System.Boolean Byte Char Decimal Double Int32
The space of the stack is limited, for a large number of logical objects, creating a class is better than creating a structure that is most often the case when the type is just some data, the best choice for the structure
Class: String object Delegate interface and so on contains a large number of logical objects, representing the abstract

5. How do you choose to be a class or a struct when customizing a type?

1). Stack space is limited, for a large number of logical objects, creating a class is better than creating a structure
2). Structures represent lightweight objects such as points, rectangles, and colors, for example, if you declare an array that contains 1000 point objects, additional memory is allocated for each object that is referenced. In this case, the cost of the structure is lower.
3). Classes are the best choice when performing abstract and multilevel object hierarchies
4). Most of the time the type is just some data when the structure is the best choice

6. What is a heap and what is a stack during the run of the. NET program?  

Stacks usually hold the steps that our code executes, and the heap is mostly objects, data, and so on. We can think of stacks as a box that is stacked together. When we use it, each time we take a box from the top of the way. The same is true of stacks, when a method (or type) is called to complete, take away from the top of the stack (called a frame, call frame), and then next. Heap is not, like a warehouse, the storage of the various objects we use information, unlike the stack is that they are not immediately cleared out.
Stack memory does not need to be managed by us or by GC. When the top element of the stack is finished, it is released immediately. The heap requires a GC (garbage collection: garbage collector) Cleanup

7. Under what circumstances will data be allocated on the heap (stack)? Do they have a difference in performance? Can the structure object be allocated on the heap? What happens and what needs attention?

1) value types are generally assigned to above, and reference types are assigned above the heap. The stack is more efficient than the heap.
2) It is possible that when a struct type is defined in a class, the structure is allocated on the heap

8. What is the role of generics? What advantages does it have? Does it have any effect on performance? What does it do at the time of execution?

Role: In order to facilitate the reuse of code, especially the reuse of algorithms
Advantages: (1) reusability (2) type safety, only data types that are explicitly desired by members in a parameterized class can use (3) Performance: Avoidance of coercion from object and boxing of value types (4) reduces memory consumption: Avoiding boxing is no longer necessary to consume memory on the heap.
Behavior at execution time: Generics are also objects, and "type parameters" of generic classes become metadata; The CLR constructs classes that take advantage of them when needed. There is no difference between a generic class and a normal class after it has been compiled. The result of compilation is only metadata and CIL. Generic instantiation based on value type: The CLR creates a materialized generic type by placing the specified type parameter in the appropriate position in the CIL. So the CLR creates a specific generic type for a new parameter value.
Instantiation based on reference type: The CLR creates a materialized generic type. Later, each time a constructed type is instantiated with a reference type parameter, and the replacement type parameter is referenced in CIL with an object, the CLR reuses the previously generated generic version

what are the generic types in the 9..NET BCL? Give an example of the generic type you define in your programming routine.

List<t>: Accessing strongly typed lists by index
Dictionary<t>: Represents a collection of key-value pairs
Queue<t>: Queue stack<t>: Stack
Shopping cart with dictionary simulation, OA to get the employee list and other data, the return value is generic

10. What is the role of the exception? What are the common exceptions in the. NET BCL? How do you catch/handle exceptions in the code? What is the difference between "throw" and "throw ex" in "catch (ex)"? How would you design the structure of the exception, and under what circumstances would you throw an exception?

(1) The C # language exception handling feature helps you to handle any unexpected or unusual conditions that occur while the program is running
(2) throw preserves stack information. Throw ex won't. Of course, if you set innerexception before you throw a new exception, you can access the original stack through the innerexception stack.
(3) by an exception to find the error, through the try catch finally to catch the exception. If it is not anticipated, do not process (memory is not enough, delete files) Direct error more easily find fault catch block from most specific to regular arrangement

What is the difference between 11.list<t> and t[] and how do you usually choose? Dictionary<tkey, what do tvalue> do? What are the common containers in the. NET BCL? How are they implemented (which data structure)? Which scenarios are applicable to each?


1.list<t>arrylist the generic version, the size is variable, t[] inherits from the array, the size is fixed. If the size does not change, choose t[], generally choose list<t>
2.Dictionary is a generic version of Hashtable, used to store key-value pairs. For example: Sortlist,stack, etc.

12 What is the difference between an abstract class and an interface? Is there anything you need to be aware of when you use it?


How do you choose to define a "complete abstraction" of an abstract class, or an interface? What is an "explicit implementation" of an interface? Why do you say it's important?
The same point: both cannot be instantiated directly, and all are implemented by inheritance with their abstract methods
Different points:
(1) The interface supports multiple inheritance, and abstract classes cannot implement multiple inheritance.
(2) An interface can define behavior only; Abstract classes can define behavior and may provide implementations.
(3) Abstract classes allow virtual members that contain implementations, so you can provide a default implementation for derived class members, and all members of an interface automatically become virtual members and cannot contain any implementation

13. Are strings referred to as type types or struct types? Reference type


Does it have anything special compared to ordinary reference types? Immutable
What do you need to be aware of when using strings? Why is it that StringBuilder is more efficient?
When stitching two strings, the system first writes two strings to memory, then deletes the original string object, creates a string object, and reads the data in memory to assign to the object. This carefree matter, it took a lot of time. This is not the case with the StringBuilder class under the System.Text namespace, which provides a append method that can be used to modify the string in place of an existing object, simply and directly.
Is it more efficient to concatenate multiple strings at any time than to add them directly?
Not necessarily, in 1000 characters or less, the efficiency of the StringBuilder class can be significantly improved when it reaches 10000.
How to efficiently perform array replication? What is the difference between a "two-dimensional array" and an "array of arrays"?
Array Copy method: For CopyTo () static CopyTo () Clone

14. What is meta-programming,. NET what meta-programming means and scenarios? What is reflection? Can you give some common scenes of reflection? Some people say that reflection performance is poor, what do you think of this problem? Is there any way to improve the performance of reflection?


When learning to do OA, dynamic loading of different dataprovider (Oracle and SQL Server) is convenient and can be replaced without recompiling the program at any time

15. What is a delegate? What is an anonymous method? In C # 3.0, what is a lambda expression? What is the extension method? What is LINQ? What are some of the important features that you find in C # 3.0, and what advantages do they bring? Which class libraries in the BCL are associated with these attributes? What do you usually use most?


A delegate can substitute a method as a parameter into another method.
A delegate can be understood as a pointer to a function.
Anonymous method: is a delegate instance that has no actual method declaration. Or, their definition is directly embedded in the code.
Lambda expression: An anonymous function syntax that is more concise than an anonymous method
Delegates and events are not comparable because the delegate is a type, the event is an object, and the following is the difference between the delegate's object (the event implemented by the delegate) and (the standard event mode implementation) event. The internal of the event is implemented with a delegate. Because for the event, external can only "register themselves + =, write off themselves--", the outside world can not write off other registrants, the outside world can not actively trigger events, so if the delegate can not carry out the above control, so the birth of the event of this grammar. An event is used to castrate a delegate instance, and an analogy is to castrate a list with a custom class. Events can only add, remove themselves, and cannot be assigned a value. Events can only be + =, =, not =. Inside the event is a private delegate and add, remove two methods.

16. What technical books, websites, communities, projects, etc. do you see outside of work?


What else do you touch? NET outside of the technology, can and. NET or. NET in a specific part of the comparison?
C # Nature theory, SQL Server2008 Combat, data structure, ASP. NET secret, JavaScript in layman's

The difference between 17.website and WebApplication


1) Website changes do not need to restart to see the effect, WebApplication need
2) Website Namespace,webapplication have namespace
3) website in order to be compatible with ASP to turn over the developer habits
4) No technical differences, different debugging habits
5) website generates a DLL for each compilation as a dll,webapplication
6) not conducive to engineering development, such as code error is not easy to find

18. Submit a form to the server to set Name,id can not be set, the server only with Name,dom ID

19. In order to distinguish between entering the page for the first time or clicking Submit again, the form has a hidden field:


<input type= "hidden" name= "IsPostBack" value= "true"/> if you read from request to Ispostback=true, the click submit button commits to enter ASHX, Otherwise it is the first time to enter ASHX

20.Http is the request-response model, the server does not read the browser's Web page, can get the data submitted by the Web page.

21.get vs. Post submissions


Get: The value of the form is passed through the URL (the default),?... &, low security, passing relatively small data.
Post: The value passed is hidden in the HTTP message, the URL is not visible, the Refresh page will pop up a prompt dialog box if

22. Achieve the text increment in P, because the server does not remember what value was last given to the browser, and does not resubmit the last value as input, so the browser needs to save the last value with a hidden field

23.ViewState Implementation principle


Non-form elements cannot pass the client's element value to the server, even if the form element can only pass value values, for other property values, such as background color, size, and so on, are not transitive, so there is a hidden field for these values. ViewState is related to the page, not the page viewstate will be different, do not affect each other. ViewState may be useful for pages that require postback processing, and for news shows such pages do not need to interact, you can disable ViewState to improve performance. If there is no viewstate at all, there is no runat=server form in the page


24.Cookie


The form is related to the page, only the browser submits the data server to obtain, the cookie is related to the site, each request to the server in addition to send the form data, and the site related to all the cookies are submitted to the server, which is mandatory
Cons: Unable to store too much information, poor security
Optimized for the Internet: Image server and master domain name are different

25.http request, Css,js, picture, individual request, 200 for processing success, 301 redirect, 400 error request

307 temporary Redirect, 404 Page Not Found, 403 forbidden, 401 unauthenticated, 500server internal error, 503 access too many.

26./: Web root directory,.. /top level directory,./current directory, ~/application root directory

27. Database Query Performance optimization

1) Only the required columns are returned in select
2) while reducing the use of columns, consider reducing rows, using the WHERE clause
3) Use order by only when needed
4) Avoid the conversion of implicit data types in the from,where and having clauses

A common sorting algorithm:

Using system;using system.collections.generic;using system.linq;using system.text;namespace Sort{public class Sort {      <summary>///Insert sort--stable sort///</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;      }}///<summary>///Hill sort///</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&      Gt public static 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--Direct Select sort///</summary>///<param name= "list" ></param> public static void Selectso         RT (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 sort///</summary>///<param name= "list" ></par am> 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];//fetch heap Top element LiSt[0] = list[i];//to move the last element in the heap up to the top of the heap list[i] = tmp;//at this time List[i] is not in the heap, used to hold ordered elements Sift (list, 0, i-1);//Heavy New Adjustment Heap}} private static void Sift (list<int> List, int low, int high)//build heap process {//i to adjust child         The index number of the root node of the tree, J for the left child of the node int i = Low, J =2* I +1; int tmp = list[i];//records the value of the parent node while (J<=high) {//If the left child is small less right operand child, then the child to be exchanged points to the right child if (J < High & amp;& List[j] < list[j +1]) {j++;//j means right child} if (TMP < LIST[J])//               If the parent node is smaller than its child node {list[i] = list[j];//Swap the parent node and its child node i = j;//with the swapped child node as root, continue to adjust its subtree            J =2* I +1;//j the left child that represents the child node of the exchange after the else//adjustment is complete {break; }} List[i] = tmp;//The initially adjusted node into the correct position}///<summary>//merge sort-stable sort///</summ ary>///<param name= "list" ></param>///<param name= "Low" ></param>///<param name= "High" ></param> public static void MergeSort (List<int> List,            int low, int.) {if (Low < high) {int mid = (low + high)/2;            MergeSort (list, low, mid);            MergeSort (list, mid +1, High);         Merge (list, low, Mid, high);         }} private static void merge (list<int> List, int low, int mid, Int. high) {//listtmp is a temporary storage space, storing the merged data         List<int> listtmp =new list<int> (high-low + 1); int i = low, J = Mid +1, K =0;//k is listtmp subscript while (I <= mid && J <= High) {list tmp[k++] = (List[i] < list[j])?         List[i++]: list[j++];         } while (I <= mid) {listtmp[k++] = list[i++];         } while (J <= High) {listtmp[k++] = list[j++]; } for (i = low, k=0; I <= high;i++,k++) {List[i] = listtmp[K];      }}///<summary>///Quick sort///</summary>///<param name= "list" ></param> public static void QuickSort (List<int> list) {QuickSort (list, 0, list).      COUNT-1);            public static void QuickSort (List<int> List, Int. Low, int.) {if (Low < high) {            int i = low, j = high, tmp = List[i];                  while (I < J) {while (I < J && List[j] >= tmp) {               j--;               } List[i] = List[j];               while (I < J && List[i] <= tmp) {i++;            } List[j] = List[i];            } List[i] = tmp;            QuickSort (list, low, i-1);         QuickSort (list, I +1, high); }      }   }}

Collected from: Gabriel Zhang

. NET Foundation question finishing

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.