TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Understand Boxing And Unboxing In C#
Vijayaragavan S
Aug 24
2016
Code
772
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
using
System;
class
BoxUboxTest {
static
void
Main(
string
[] args) {
int
m = 10;
object
a = m;
// boxing
try
{
Console.WriteLine(
"Value of m is:"
+ a);
// unbox
object
n = 20;
int
b = (
int
) n;
Console.WriteLine(
"Value of n is:"
+ b);
System.Console.WriteLine(
"Unboxing OK."
);
Console.ReadKey();
}
catch
(System.InvalidCastException e) {
System.Console.WriteLine(
"Error: Incorrect unboxing."
+ e.Message);
}
}
}
Understand Boxing
Unboxing
C#