programming-examples/c-sharp/Functions/C# Program to Demonstrate Boxing Operations.cs

39 lines
817 B
C#
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*
* C# Program to Demonstrate Boxing Operations
*/
using System;
class sample
{
int x = 10;
object obj;
void boxmethod()
{
sample s= new sample();
bool b;
object ob="CSHARP";
b=s.obj is int;
Console.WriteLine(b);
s.obj = x;
b = s.obj is int;
Console.WriteLine("{0},{1},{2}",s.obj,s.x,b);
s.x = (int)s.obj;
s.x = 20;
b = s.obj is int;
Console.WriteLine("{0},{1},{2}", s.obj, s.x, b);
s.obj="CSHARP";
b=s.obj is int;
Console.WriteLine("{0},{1},{2}",s.obj,s.x,b);
Console.ReadLine();
}
public static void Main()
{
sample s=new sample();
s.boxmethod();
}
}
/*
False
10,10,True
10,20,True
CSHARP,20,False