Typical C # interview questions

Source: Internet
Author: User
1. in C #, use text or images to describe the differences between string STR = NULL and string STR =.
Key answer: Describe the detailed space allocation. (10 points)
A: String STR = NULL indicates that no memory space is allocated to it, while string STR = "" indicates that it is allocated with a memory space of a null string.

2. Describe the similarities and differences between classes and struct in DOTNET: (10 points)
A: The class can be instantiated. It belongs to the reference type and is allocated to the memory stack. The struct belongs to the value type and is allocated to the memory stack.

3. Based on the delegate knowledge, complete the following user controls:CodeFragment: (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 ))

{
// Complete the following code to call the onnew event of the ondboperate delegate signature.

}

}

}

A: If (onnew! = NULL)
Onnew (this, e );

4. Analyze the following code to complete the blanks (10 points)
String strtmp = "abcdefg ";
Int I = system. Text. encoding. Default. getbytes (strtmp). length;
Int J = strtmp. length;
After the above code is executed, I = J =

Answer: I = 13, j = 10

5. In the sqlserver server, there are two field IDs and lastupdatedate in the given table 1. The ID indicates the updated transaction number, and the lastupdatedate indicates the server time during the update, use an SQL statement to obtain the last updated transaction number. (10)

A: Select ID from Table1 where lastupdatedate = (select max (lastupdatedate) from Table1)

6. Based on the knowledge of thread security, analyze the following code. Will the deadlock occur when I> 10 is called when the test method is called? And briefly explain the reasons. (10 points)

Public void test (int I)

{
Lock (this)
{
If (I> 10)

{

I --;

Test (I );

}

}

}

A: No deadlock will occur (but one int is passed by value, so each change is only a copy, so no deadlock will occur. But if you replace int with an object, 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 correctly use the connection pool?

Answer: If the input connectionstring is the same, you can use the connection pool correctly. But exactly the same means that the numbers of spaces in the hyphen are in the same order.

2) can all exceptions in the test method be captured and displayed in the exception handling method used by the above Code?

A: You can only catch exceptions in database connections. (In finally, catch, if there are other operations that may cause exceptions, try and catch should also be used. So theoretically not all exceptions will be caught .)

8. Briefly discuss your understanding of the remoting and WebService technologies under the Microsoft. NET architecture and their practical applications. (10)

A: Ws uses http to penetrate the firewall. Remoting can improve the efficiency by using TCP/IP and binary transmission.

9. The company requires the development of a component that inherits the system. Windows. Forms. listview class and requires the following special features: Click the column headers of the listview
You can sort all rows in the view according to the values of each row in the click column (the order is similar to that in the DataGrid ). Based on your knowledge, please briefly discuss your ideas: (10)

A: Based on the column header clicked, the ID of this column is taken out, sorted by the ID, and bound to the listview

10. Specify the following XML file to completeAlgorithmFlowchart. (10)

<Filesystem>
<Driverc>
<Dir dirname = "msdos622">
<File filename = "command.com"> </File>
</Dir>
<File filename = "msdos. sys"> </File>
<File filename = "Io. sys"> </File>
</Driverc>
</Filesystem>

Draw a flowchart that traverses all file names (filename) (use recursive algorithms ).

A:
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 );
}

}

simply put, it is to traverse the child node from the root node and find its child node from the child node.

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.