Home  >  Article  >  Backend Development  >  What is unboxing in C#?

What is unboxing in C#?

WBOY
WBOYforward
2023-09-12 13:13:11862browse

What is unboxing in C#?

Boxing is implicit, unboxing is explicit. Unboxing is the explicit conversion of a reference type created by boxing back to a value type.

Let us see an example of variables and objects in C# −

// int
int x = 30;

// Boxing
object obj = x;

// Un boxing
int unboxInt = (int) obj;

The following is an example that shows Un boxing −

int x = 5;
ArrayList arrList = new ArrayList();

// Boxing
arrList.Add(x);

// UnBoxing
int y = (int) arrList [0];

The above is the detailed content of What is unboxing in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete