You are developing an application by using C#. The application includes the following code segment. (Line
numbers are included for reference only.)
01 public interface IDataContainer
02 {
03 string Data { get; set; }
04 }
05 void DoWork(object obj)
06 {
07
08 if (dataContainer != null)
09 {
10 Console.WriteLine(dataContainer.Data);
11 }
12 }
The DoWork() method must throw an InvalidCastException exception if the obj object is not of type
IDataContainer 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.
dataContainer = obj as IDataContamer;
C.
var dataContainer = obj is IDataContainer;
D.
dynamic dataContainer = obj;
Explanation:
http://msdn.microsoft.com/en-us/library/ms173105.aspx