Usually C # face questions

Source: Internet
Author: User

1. In C #, string str = null and string str = "" Try to use text or images to illustrate the difference.


Main answer: Explain the detailed space allocation. (10 points)


A: string str = NULL does not allocate memory space to him, and string str = "" Assigns it a memory space with an empty string length.

2. Please elaborate on the similarities and differences between class and structure (struct) in dotnet: (10 points)


A: Class can be instantiated, belongs to the reference type, is allocated on the memory heap, struct belong to the value type, is allocated on the memory stack.


3, according to the knowledge of the delegate (delegate), please complete the following user controls in the code fragment fill: (10)


Namespace test


{


public delegate void Ondboperate ();


public class UserControlBase:System.Windows.Forms.UserControl


{


public event Ondboperate OnNew;


Privatevoidtoolbar_buttonclick (Objectsender,system.windows.forms.toolbarbuttonclickeventargs e)


{


if (E.button.equals (btnnew))


{


Please use the following completion code to invoke the OnNew event of the Ondboperate delegate signature.


}


}


}


Answer: if (onnew!= null)


OnNew (this, e);

4, analyze the following code, complete the fill in the blanks (10 points)


String strtmp = "ABCDEFG a so-and-so";


int i= System.Text.Encoding.Default.GetBytes (strtmp). Length;


int j= strtmp.length;


After the above code executes, i= j=


Answer: i=13,j=10

5, SQL Server servers, the given table table1 has two field IDs, Lastupdatedate,id represents the updated transaction number, Lastupdatedate represents the server time when the update, use a SQL statement to get the last updated transaction number. (10)


Answer: SELECT ID


From table1


WHERE lastupdatedate = (SELECT MAX (lastupdatedate) from table1)


6, according to the relevant knowledge of thread safety, analysis of the following code, when the test method is invoked when i>10 will cause deadlock? and briefly explain why. (10 points)


public void Test (int i)


{


Lock (This)


{


if (i>10)


{


i--;


Test (i);


}


}


}


A: There is no deadlock, (but there is a point int is passed by value, so each change is just a copy, so there is no deadlock.) But if an int is changed to an object, then the deadlock will occur.

7, analyze the following code. (10)


public static void Test (String connectstring)


{


System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection ();


Conn. ConnectionString = connectstring;


Try


{


Conn. Open ();


.......


}catch (Exception Ex)


{


MessageBox.Show (Ex.tostring ());


}finally


{


if (!conn. State.equals (connectionstate.closed))


Conn. Close ();


}


Excuse me


1) Can the above code use the connection pool correctly?


Answer: If the incoming connectionstring is exactly the same, you can use the connection pool correctly. But the exact same meaning is that the number of spaces in the hyphen is exactly the same as the order.


2 The exception handling method used by the above code, whether all the exceptions within the test method can be captured and displayed?


A: You can only catch exceptions in a database connection. (Finally, in catch, if there are other actions that might throw an exception, you should also use Try,catch.) So in theory not all anomalies will be captured. )


8. Briefly discuss your understanding and practical application of the remoting and WebService two technologies under Microsoft. NET Framework. (10)


A: WS is primarily available to use HTTP to penetrate firewalls. and remoting can use TCP/IP, binary transmission to improve efficiency.

9, the company requires the development of a successor System.Windows.Forms.ListView class components, requirements to achieve the following special features: Click ListView Column Header, you can click on the column of each row of values to rearrange the view of all rows ( Sort in the same way as a DataGrid). According to your knowledge, please briefly talk about your ideas: (10)


A: According to the click of the column header, package the ID of the column out, sorted by that ID, after the binding to the ListView

10, given the following XML file, complete the algorithm flowchart. (10)


<FileSystem>


< DRIVERC >


<dir dirname= "MSDOS622" >


<file FileName = "Command.com" ></File>


</Dir>


<file FileName = "MSDOS." SYS "></File>


<file FileName = "IO." SYS "></File>


</DriverC>


</FileSystem>


Please draw a flowchart that traverses all file names (filename) (using a recursive algorithm).


For:


void FindFile (Directory D)


{


Fileorfolders = D.getfileorfolders ();


foreach (Fileorfolder fof in Fileorfolders)


{


if (FoF is File)


You Found a file;


else if (FoF is Directory)


FindFile (FOF);


}


}


The simple thing is to start by traversing the root node to find the child node, to find its child node from the found child node, layer by layer



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.