Boxing and Unboxing in .NET
Am looking for the exact answer to find out in what way that boxing and unBoxing are used in .NET
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tapan PatelRank #614 · 3.9K reputationPosted Sep 1, 2016, 6:14 AM EDT
If you know the difference between stack and heap à any variable (of primitive data types like int , bool, double and so on ) gets stored on the stack where as any object is stored on the different data structure of the memory called heap.
Consider below example.
If you look at statement for int and bool, CLR allocates memory on the stack.
So if you do something (a standard example) like this:
That is why it is advisable not to use Int or Boolean , instead use int, bool so that you will save some time that makes CLR to move code from stack to Heap. So bottom line is , if you don't need it, don't use it as it causes performance hits.
Please mark it as an answer if addresses the issue.
Krishna Rajput SinghRank #605 · 4K reputationPosted Sep 1, 2016, 5:38 AM EDT
Midhun TpRank #388 · 6.5K reputationPosted Sep 1, 2016, 5:21 AM EDT
Menaka Priyadharshini BRank #341 · 7.3K reputationPosted Sep 1, 2016, 6:17 AM EDT