需要注意的 MCSD 题目 316, 1

Question

You use Visual Studio .NET to create a control that will be used on several forms in your application.
It is a custom label control that retrieves and displays your company’s current stock price.
 
The control will be displayed on many forms that have different backgrounds. You want the control
to show as much of the underlying form as possible. You want to ensure that only the stock price is
visible. The rectangular control itself should not be visible.
 
You need to add code to the Load event of the control to fulfill these requirements. Which two code
segments should you use? (Each correct answer presents part of the solution. Choose two)
 
A.  this.BackColor = Color.Transparent;
B.  this.ForeColor = Color.Transparent;
C.  this.BackImage = null;
D.  this.SetStyle(ControlStyles.UserPaint, false);
E.  this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
 
 
Answer: A, E
Explanation: 
To give your control a transparent backcolor:
1.  Call the SetStyle method of your form in the constructor. 
 
this.setStyle(ControlStyles.SupportsTransparentBackColor, true);
This will enable your control to support a transparent backcolor. 
2.  Beneath the line of code you added in step 1, add the following line. This will set your control's
BackColor to Transparent. :
 
this.BackColor = Color.Transparent;

Question

You use Visual Studio .NET to develop an application that contains 50 forms. You create a procedure
named PerformCalculations, which writes the results of several internal calculations to the Debug
window. These calculations take more than one minute to execute.
 
You want to be able to compile two versions of the application, one for debugging and the other for
release. The debugging version should execute the calculations. The release version should not include
or compile the calculations. You want to accomplish this goal by using the minimum amount of code.
 
Which two actions should you take? (Each correct answer presents part of the solution. Choose two)
 
A.  Use the following code segment:
#if DEBUG
// Insert code to perform calculations.
#endif
B.  Use the following code segment:
if (DEBUG) {
// Insert code to perform calculations.
}
C.  Use the following code segment at the top of the module:
#define DEBUG
D.  Add DEBUG = true to the Command Line Arguments box on the Debugging pane of the Project
Properties dialog box.
E.  Ensure that the Conditional Compilation Constants option in the Build pane of the Project
Properties dialog box contains the value DEBUG.
F.  Ensure that the Conditional Compilation Constants options in the Build pane of the Project
Properties dialog box includes the value TRACE.
 
 
Answer: A, E
Explanation: 
A: We should use the #if DEBUG conditionally statement wherever we want to use code that print debug
information. 
E: We enable debugging by entering DEBUG to the Conditional Compilation Constants option.
 
Reference: 
Visual Basic and Visual C# Concepts, Compiling Conditionally with Trace and Debug
C# Language Specification, Conditional compilation directives
 
Incorrect Answers
B: Incorrect syntax.
C: This would achieve the goal as well. But compared to E) it would not minimize code.
D: This is not how it is done in C#. In Visual Basic .NET you could use #CONST DEBUG = true. In
Visual C# however, you must use the DEBUG = true statement.
F:  Traces are used to trace program execution, not to print debug information.
 

Question

You develop a Windows-based application by using Visual Studio .NET. The application includes
numerous method calls at startup. After optimizing your application code, you test the application on
a variety of client computers. However, the startup time is too slow.
 
You must ensure that your application starts as quickly as possible the first time it runs. What should
you do?
 
A.  Precompile your application by using the Native Image Generator (Ngen.exe):
Install the precompiled application on the client computers.
B.  Install your application on the client computers.
Precompile your application by using the Native Image Generator (Ngen.exe).
C.  Precompile your application by using the JIT compiler.
Install the precompiled application on the client computers.
D.  Install your application on the client computers.
Precompile your application by using the JIT compiler.
 
 
Answer: B
Explanation: The Native Image Generator creates a native image from a managed assembly and installs it
into the native image cache on the local computer. Running Ngen.exe on an assembly allows the assembly
to load and execute faster, because it restores code and data structures from the native image cache rather
than generating them dynamically.
The native image contains processor-specific machine code and in this scenario a variety of client computers
are used. We must therefore use the Ngen.exe utility at the client computers after the installation, not at the
Development computer..
 
Reference: 
.NET Framework Tools, Native Image Generator (Ngen.exe)
70-306/70-316 Training kit, Installing a Native Assembly Image, Page 495
.NET Framework Developer's Guide, Compiling MSIL to Native Code
 
Incorrect Answers
A: The Native Image produced by Ngen.exe is machine-specific and in this scenario a variety of client
computers are used. We cannot use the a single Native Image from once computer on all the other
computers..
C, D: JIT (just-in-time) compilation occurs at run-time, and cannot be precompiled.
Note: When you compile a .NET application, it is not compiled to binary machine code; rather, it is
converted to IL, which is a low-level set of instructions understood by the common language run time.

When execution starts, the first bit of code that needs to be executed is loaded into memory and
compiled into native binary code from IL by the common language run time's Just-In-Time (JIT)
compiler.
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值