What is unboxing in C#?

WBOY
Release: 2023-09-12 13:13:11
forward
875 people have browsed it

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;
Copy after login

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];
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!