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
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mursaleen fayyaz
NA
84
125.6k
Boxing/unboxing and Performance ?
Jun 2 2013 2:32 PM
The conversion from a value type to a reference type is known as boxing. Boxing happens automatically if a method requires an object as a parameter and a value type is passed. On the other side, a boxed value type can be converted to a value type by using unboxing. With unboxing, the cost operator is required.
var list = new ArrayList();
list.Add(44); //boxing, convert a value type to a reference type.
int i1 = (int)list[0]; //unboxing, convert a reference type to a value type.
foreach(int i2 in list)
{
Console.WriteLine(i2);
}
Note: Boxing and unboxing are easy to use but have a big performance impact, especially when iterating through many times.
Instead of using ArrayList, use the List<T> class from the namespace
System.Collections.Generic
var list = new List<int>();
list.Add(44);
int i1 = list[0];
foreach(int i2 in list)
{
Console.WriteLine(i2);
}
Comments are Welcome.
Reply
Answers (
1
)
i am working on liquor bar bill management project
Put DataList into Session Object