Users Online

· Guests Online: 110

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Perform Unboxing Operation

C# Program to Perform Unboxing Operation

 

This is a C# Program to perform unboxing operation.

Problem Description

This C# Program Performs Unboxing Operation.

Problem Solution

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.

Program/Source Code

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();
    }
}
Program Explanation

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.

Runtime Test Cases
 
Data : 50
Data : 0

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.02 seconds
10,853,818 unique visits