Please suggest..
which among the following are unboxing example:
enum E={"Hello World"};
void sample(System.Enum et)
{
E e = (E) et;
}
OR
class C = {public int Value{get;set;}}
void sample1(C ct)
{
int i = ct.Value;
}
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jan 24, 2012, 11:13 PM
Unboxing is an explicit conversion from the type object to a value type or from an interface type to a value type that implements the interface. An unboxing operation consists of:
- Checking the object instance to make sure it is a boxed value of the given value type.
- Copying the value from the instance into the value-type variable.
int i = 123; // A value typeobject box = i; // Boxing
int j = (int)box; // Unboxing
here enum is value type
refer http://msdn.microsoft.com/en-us/library/s1ax56ch%28v=vs.80%29.aspx
so there is no unboxing.
hope this help.
Alok UniyalPosted Jan 24, 2012, 4:27 AM