MS 考试 70-536 准备:有效使用 TextWriter - 练习测试答案是错误的(我认为)!
我正在参加 70-536 考试的模拟考试。下面是一个屏幕截图。黄色突出显示的是考试所说的正确答案。选中单选按钮的那个就是我认为的答案。
请注意底部的解释,其中包括以下语句:
要创建
StreamWriter
对象,您必须使用现有的Stream
对象,例如FileStream
的实例。
我认为我选择的答案是最有效的用途,并且我认为解释中的陈述是错误的。显然,因为我选择的答案中的代码运行良好。
谁说得对???
I'm taking a practice test for the exam 70-536. Below is a screenshot. The yellow highlighted is what the exam says is the correct answer. The one with the radio button selected is the answer I thought it was.
Note the explanation at the bottom which includes the statement:
To create a
StreamWriter
object, you must use an existingStream
object, such as an instance ofFileStream
.
I think the answer I chose is the most efficient use and I think the statement made in the explanation is wrong. Clearly, because the code in my selected answer worked fine.
Who's right????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您选择的答案中,C# 和 VB.NET 版本之间存在差异。 VB.NET 版本甚至无法编译,而 C# 版本是正确的。
这不会编译:
这没关系:
最后一个答案是不可能的,因为 TextWriter 是一个抽象类,你不能直接实例化它。
但显然,您在现实应用程序中使用的正确答案甚至不存在于列表中。它将是:
或者如果您需要使用
Stream
:In the answer you choose there's a difference between the C# and VB.NET version. The VB.NET version won't even compile whereas the C# is correct.
This won't compile:
This is OK:
The last answer is out of the question because TextWriter is an abstract class and you cannot instantiate it directly.
But obviously the correct answer which is what you would use in a real world application is not even present in the list. It would be:
or if you need to use a
Stream
:他们是对的 - 您不能将 TextWriter 设置为等于 FileStream 的实例,因为 FileStream 不是从 TextWriter 继承的 - 您需要使用基于 FileStream 的 StreamWriter,因为 StreamWriter 确实继承自 TextWriter。
They're right - you can't set a TextWriter equal to an instance of FileStream as FileStream does not inherit from TextWriter - you need to use a StreamWriter based on the FileStream as StreamWriter does inherit from TextWriter.