Data : 50 Data : 0
This is a C# Program to perform unboxing operation.
This C# Program Performs Unboxing Operation.
Here 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.
Here is source code of the C# Program to Perform Unboxing Operation. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Perform Unboxing Operation */ using System; class sample { int data; void insert(object x) { data = (int)x * 5; } object delete() { data=0; return (object)data; } public static void Main() { sample s = new sample(); s.insert(10); Console.WriteLine("Data : {0}", s.data); Console.WriteLine("Data : {0}", s.delete()); Console.ReadLine(); } }
In this C# Program, we are performing the unboxing operation. In sample class we have created insert() and delete() function. The insert() function use data variable to multiply the value of argument with the value of 5.
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. Using object variable‘s’ we are passing the value 10 to the insert() function as an argument.
Data : 50 Data : 0