You are developing an application by using C#. The application includes the following code segment.
(Line numbers are included for reference only.)
The DoWork() method must not throw any exceptions when converting the obj object to the
IDataContainer interface or when accessing the Data property.
You need to meet the requirements. Which code segment should you insert at line 07?
A.
var dataContainer = (IDataContainer)obj;
B.
dynamic dataContainer = obj;
C.
var dataContainer = obj is IDataContainer;
D.
var dataContainer = obj as IDataContainer;
Explanation:
As – The as operator is like a cast operation. However, if the conversion isn’t possible, as returns null
instead of raising an exception.
http://msdn.microsoft.com/en-us/library/cscsdfbt(v=vs.110).aspx
D
D
d
D
object as class returns the object converted into the class if the obj is compatibile with that class. if obj is not compatible the statement returns null.
A would work but will throw an invalidcastexcept if value is not the appropriate type.
so D
Sadly the exam got updated this March, here’s the new dump for who’s doing the exam soon.
There’s like 20 new questions with a new case study.
http://megadownloder.com/70483ProgrammingInC
go and fu k yourself
B is a widening conversion so requires casting
C is only a test if hte obj is a compatible with the type not just if the obj actually is of that type.
* D *
You can use the As operator to perform certain types of conversions between compatible reference types or nullable types.