C # Programmers interview (i) answer

Source: Internet
Author: User
Tags error code execution garbage collection
Program | Programmer Prerequisites: The status bar panel Sbpfilepath has been set to a custom style. When the following code segment 1 is executed once:

Code Snippet 1:
private void Treeviewarchives_afterselect (object sender, System.Windows.Forms.TreeViewEventArgs e)
{
if (e.node.text!= "")
{
Try
{this.richtexebox.LoadFile (Application.startuppath+e.node.text);
Statusmessages=e.node.text;
Sbpfilepath.text=statusmessages;//statusmessages represents a String
}
Catch
{MessageBox.Show ("Error loading file, unable to display!");
}
}
}

Code Snippet 2:
private void Statusbar1_drawitem (object sender, System.Windows.Forms.StatusBarDrawItemEventArgs sbdevent)
{//Draw panel area
Sbdevent. Graphics.FillRectangle (Brushes.green, sbdevent. Bounds);
Draw text on a panel
Sbdevent. Graphics.DrawString (statusmessages,sbdevent. Font,brushes.white,sbdevent. Bounds);
Sbdevent. Graphics.dispose ();
}

Test questions:

1, code paragraph 2 will not be implemented?
Answer: Yes.

2, code paragraph 2 if not executed, why? How do I modify it?
Answer: too. Go on to the next question.

3, the Code section 2 if will be executed, will be repeated execution (that is, continuous execution two or more times)?
Answer: Yes.

4, code Segment 2 if repeated execution, how to modify so that only run once is enough?
Answer: Code snippet 1 can be modified to:
private void Treeviewarchives_afterselect (object sender, System.Windows.Forms.TreeViewEventArgs e)
{
if (e.node.text!= "")
{
Try
{
This.richtexebox.LoadFile (Application.startuppath+e.node.text);
Statusmessages=e.node.text;
Comment out the following sentence and add the method of force rendering
Sbpfilepath.text=statusmessages;//statusmessages represents a String
Statusbar1.invalidate ();
}
Catch
{MessageBox.Show ("Error loading file, unable to display!");
}
}
}

5, Code section 2 sbdevent. Graphics.dispose ()//This statement is not optional, why?
Answer: To release resources as far as possible, as long as the compilation and operation of the process is not wrong, should be added.
(If the scene is disputed, leave the list, let him go back to test, the next day with the test report again)


6. Suppose you run the following statement
{sbpfilepath.text=statusmessages;sbpfilepath.text=statusmessages;}
Questions with the above 1-3, please answer again.
Answer: If you do not modify code Snippet 1, this statement segment runs at the first time
Sbpfilepath.text=statusmessages;
, Code snippet 2 is run two times, and thereafter, as long as the value of the sbpfilepath.text is unchanged,
That is, the StatusMessages value does not change, then code Segment 2 does not continue to run.
That
{sbpfilepath.text=statusmessages;sbpfilepath.text=statusmessages;}
is equivalent to
Sbpfilepath.text=statusmessages;

7. Do you think that code Segment 1 or Code section 2 has no errors? (You don't have to answer the question if you think you answered the question above.)
Answer: syntax is not wrong, but can modify the code, reduce redraw, save resources.

8, some people think that C # developed the program is too slow, how do you think of this problem? Do you prioritize people-oriented, user-focused thinking in the coding process?
Please brief.
Answer: Part of the truth, the other part is that many people rely entirely on automatic garbage collection without considering weak references, Dispose (), Close (),
GC, and so on, and even a lot of people taboo try-catch-finally, causing exaggerated problems, C # Development of the real problem lies in the current cross-platform aspects.
The company's research and development department thinks: if Java developers think that C # developed the program is too slow, certainly not a qualified Java programmer, he wrote the code is sure
Low performance, resource-intensive. If 2 times after the reminder, he also insisted on this point of view, is certainly an impetuous person, avoid use.
Recruitment process Note: Do not try to guide candidates to compare language differences, not to publish biased language views, pay attention to the candidate's mood.

9, generally believe that the following books are classic, if you have read, please pick any book from the inside, pointing out that the book 5 more serious impact on the speed of the program code section
or an error code. (I hope to emphasize the principle of our company: the level of programmers, is to see his code and code performance, not to see how much he learned,
Nor look at his seniority)
Answer:
The information is not available.

I have kept my promise and have not posted more topics on other websites for the time being.
And absolutely no technical questions or answers are published except this article.
Once the 3rd round of recruitment results are released, I will upload the first time to the Internet,
Attention, everybody.

Many people can teach me, I will cherish the opportunity to teach ...




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.