Add. NET knowledge

Source: Internet
Author: User
Tags modifiers

Question 1:

  Public intGetValueinta) {Try{a= A +1; returnA = a +2; }            Catch(Exception) {Throw; }            finally{a= A + -; }        }

int a = GetValue (3);

What is the value of a? Generally must think: finally is certain to execute, so the answer is 56

But the reality is that Retun is executed before finally

So the answer is 6.

2.new has several uses

There are three ways to use this: in C #,Newkeywords can be used as operators, modifiers, or constraints. 1)Newoperator: Used to create objects and invoke constructors. This kind of people are more familiar with, there is nothing to say. 2)NewModifier: When used as a modifier,Newkeyword to explicitly hide members that inherit from a base class. 3)Newconstraint: Used to constrain the type of a parameter that may be used as a type parameter in a generic declaration. See the following example for the second usage:usingSystem;namespaceconsoleapplication1{ Public classBasea { Public intx =1;  Public voidInvoke () {Console.WriteLine (x.tostring ()); }         Public intTrueValue {Get{returnx;} Set{x =value;} }    }     Public classDerivedb:basea {New  Public intx =2; New  Public voidInvoke () {Console.WriteLine (x.tostring ()); }        New  Public intTrueValue {Get{returnx;} Set{x =value;} }    }     classTest {Static voidMain (string[] args) {Derivedb B=NewDerivedb (); B.invoke ();//call Derivedb's Invoke method, output: 2Console.WriteLine (B.x.tostring ());//member of output derivedb x value: 2Basea A =b; A.invoke ();//call Basea's Invoke method, output: 1A.truevalue =3;//Call the Basea property TrueValue, modify the value of BASEA member XConsole.WriteLine (A.x.tostring ());//value of member X for output Basea: 3Console.WriteLine (B.truevalue.tostring ());//The value of the member X of the output derivedb, which is still: 1//It can be seen that to access the member variables, properties, or methods of the hidden base class, the subclass is styled as a parent class, and//The hidden member variable, property, or method is accessed through the base class. }}} The new constraint specifies that any type parameter in a generic class declaration must have a public parameterless constructor. Take a look at the following example:usingSystem;usingSystem.Collections.Generic;namespaceconsoleapplication2{ Public classEmployee {Private stringname; Private intID;  PublicEmployee () {name="Temp"; ID=0; }          PublicEmployee (stringSinti) {name=s; ID=i; }          Public stringName {Get{returnname;} Set{name =value;} }          Public intID {Get{returnID;} Set{id =value;} }    }     classItemfactory<t>whereT:New()    {         PublicT Getnewitem () {return NewT (); }    }      Public classTest { Public Static voidMain () {itemfactory<Employee> employeefactory =NewItemfactory<employee>(); ////Here The compiler checks to see if the employee has a public parameterless constructor.             //if not, the Employee must has a public parameterless constructor error. Console.WriteLine ("{0} ' ID is {1}.", Employeefactory.getnewitem ().        Name, Employeefactory.getnewitem (). ID); }}} See the explanation for new on MSDNNewmodifier (C # Reference) when used as a modifier,NewKeyword to explicitly hide members that inherit from a base class. When you hide an inherited member, the derived version of the member replaces the base class version. Although you can not use theNewModifier to hide a member, but a warning is generated. If you useNewexplicitly hiding a member, this warning is canceled and the fact that you want to replace it with a derived version is logged. To hide an inherited member, declare the member in the derived class with the same name, and use theNewModifier to decorate the member. For example: Public classbasec{ Public intx;  Public voidInvoke () {}} Public classderivedc:basec{New  Public voidInvoke () {}} In this example, Derivedc.invoke hides Basec.invoke. field x is not affected because it is not hidden by a field that resembles a name. Hiding names by inheritance takes one of the following forms: the introduction of constants, designations, attributes, or types in a class or struct hides all base class members with the same name. Introduce methods in a class or struct to hide properties, fields, and types that have the same name in the base class. It also hides all base class methods with the same signature. Introducing indexers in a class or struct hides all base class indexers with the same name. Simultaneous use of the same memberNewAndOverrideis a bad practice because the meanings of these two modifiers are mutually exclusive.NewModifier creates a new member with the same name and turns the original member into a hidden one.Overridemodifiers extend the implementation of inherited members. Use in declarations that do not hide inherited membersNewmodifier will generate a warning. In this example, the base class Basec and the derived class Derivedc use the same field name X, which hides the value of the inherited field. This example demonstrates theNewthe use of modifiers. It also demonstrates how to use a fully qualified name to access hidden members of the base class.  Public classbasec{ Public Static intx = -;  Public Static inty = A;} Public classderivedc:basec{//Hide field ' x '.    New  Public Static intx = -; Static voidMain () {//Display The new value of x:Console.WriteLine (x); //Display The hidden value of x:Console.WriteLine (basec.x); //Display the Unhidden member Y:Console.WriteLine (y); }}/*output:1005522*/in this example, a nested class hides a class with the same name in the base class. This example demonstrates how to use theNewmodifier to dismiss the warning message, and how to use the fully qualified name to access the hidden class member.  Public classBasec { Public classNestedc { Public intx = $;  Public inty; }} Public classderivedc:basec {//Nested type hiding the base type members.    New  Public classNestedc { Public intx = -;  Public inty;  Public intZ; }    Static voidMain () {//Creating An object from the overlapping class:Nestedc C1 =NewNestedc (); //Creating An object from the hidden class:BASEC.NESTEDC C2 =NewBasec.nestedc ();        Console.WriteLine (c1.x);       Console.WriteLine (c2.x); }}/*output:100200*/

What is the maximum length of 3.varchar and nvarchar respectively, and what is the difference?

1.nvarchar (n): variable-length Unicode character data with n characters. The value of n must be between 1 and 4,000. The storage size of bytes is twice times the number of characters entered. The input data character length can be zero.
2.varchar[(n)]: variable-length, non-Unicode character data with a length of n bytes. n must be a numeric value between 1 and 8,000. Storage size is the actual length of bytes of input data, not n bytes. The input data character length can be zero.
2. Difference:
1. From the storage mode, nvarchar is stored by character, while varchar is stored by byte;
2. In terms of storage, varchar saves space because the storage size is the actual length of bytes, while nvarchar is a double-byte storage;
3. In the use, if the storage contents are English characters and no other language symbols such as Chinese characters, it is suggested to use varchar, containing the use of Chinese characters nvarchar, because nvarchar is the use of Unicode encoding, that is, the uniform character encoding standard, will reduce the likelihood of garbled characters;
4. If you are doing a project that may involve conversion between different languages, it is recommended to use nvarchar.

4. What is the concept of a database page?

。 For SQL Server, each file is a long list of bytes. SQL Server logically (just logically, not physically) divides this file into N-8K chunks. This block is called a page. The first 8K block of a database file is page #0, and the next 8K block is page # #, and so on. The page is the smallest unit of IO read, and SQL Server involves a page for every IO read and write, and of course, for multiple physically contiguous pages, SQL Server can all be completed with one IO

There is a specific article: http://www.cnblogs.com/CareySon/archive/2012/09/07/2674503.html

5. When the transaction is updated, the other tables can be read, the answer is determined by the transaction level, different levels, different effects, there will be dirty read, some will be a deadlock

There is a specific article: http://blog.csdn.net/dinglang_2009/article/details/7204253

Http://www.cnblogs.com/qanholas/archive/2012/05/02/2479340.html

Add. NET knowledge

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.