boxing Questions

6

Solved

Another recent C# interview question I had was if I knew what Boxing and Unboxing is. I explained that value types are on Stack and reference types on Heap. When a value is cast to a reference type...
Sethsethi asked 18/4, 2009 at 21:10

6

Solved

This is not a question of what is boxing and unboxing, it is rather why do languages like Java and C# need that ? I am greatly familiar wtih C++, STL and Boost. In C++ I could write something lik...
Drumfish asked 24/6, 2009 at 19:19

1

Solved

Vector.min is implemented as def min[B >: A](implicit cmp: Ordering[B]): A = { if (isEmpty) throw new UnsupportedOperationException("empty.min") reduceLeft((x, y) => if (cmp.lteq(x, y)) x...
Bungle asked 24/5, 2012 at 6:48

3

Solved

Actually, I should've asked: how can I do this and remain CLS Compliant? Because the only way I can think of doing this is as follows, but using either __makeref, FieldInfo.SetValueDirect or just S...
Batey asked 29/3, 2012 at 14:36

1

Solved

What I understand unboxing is when I take a object and unbox it to valuetype like the MSDN example: int i = 123; object o = i; o = 123; i = (int)o; // unboxing So I just was thinking, can a str...
Ng asked 23/3, 2012 at 16:34

2

Solved

We have some code that archives data from a Microsoft Access database into a MS SQL Server database. Assuming we have a data reader already populated from the Access table and we are adding a param...
Vinny asked 16/3, 2012 at 17:25

6

Solved

Consider: int a = 42; // Reference equality on two boxed ints with the same value Console.WriteLine( (object)a == (object)a ); // False // Same thing - listed only for clarity Console.WriteLine(...
Relique asked 23/11, 2010 at 14:8

3

Solved

I have a situation where I have a simple, immutable value type: public struct ImmutableStruct { private readonly string _name; public ImmutableStruct( string name ) { _name = name; } publi...
Pentstemon asked 22/8, 2011 at 16:51

3

Solved

I am curious to know if all casts in C# result in boxing, and if not, are all casts a costly operation? Example taken from Boxing and Unboxing (C# Programming Guide) int i = 123; // The followi...
Growing asked 20/2, 2012 at 18:15

5

Solved

My question is somewhat related to this one: Explicitly implemented interface and generic constraint. My question, however, is how the compiler enables a generic constraint to eliminate the need f...
Argentina asked 3/4, 2011 at 19:36

3

Solved

I'm having a hard time understanding this. Consider the following example: protected void Page_Load(object sender, EventArgs e) { // No surprise that this works Int16 firstTest = Convert.ToInt16...
Brandi asked 7/1, 2012 at 17:12

4

Solved

I'm working on a project in which we are producing a language which compiles to java. The framework we are using (xtext) makes prolific use of boxing in its generated code. Specifically, if you hav...
Mook asked 11/12, 2011 at 23:9

2

Solved

Let's say I have interface IMatrix { double this[int r, int c] { get; } } struct Matrix2x2 : IMatrix { double a1, a2, b1, b2; double this[int r, int c] { get { ... } } } struct Matrix3x3 : IM...
Nakano asked 3/12, 2011 at 20:33

1

Solved

I recently did some rough performance measuring on List<> vs [] for an array of small structures. System.Array seemed to win hands down so I went with that. It's only just dawned on me that ...
Phira asked 21/11, 2011 at 15:7

7

Solved

The code I'm writing receives an ArrayList from unmanaged code, and this ArrayList will always contain one or more objects of type Grid_Heading_Blk. I've considered changing this ArrayList to a gen...
Overshadow asked 7/6, 2010 at 18:19

2

Solved

Does the following have any performance issues (e.g. performing boxing)? public int CompareIntValues(int left, int right) { return left.CompareTo(right); } Some further information. The applica...
Aeri asked 23/8, 2011 at 14:7

2

Solved

Let's imagine one retrieves the declaring type of a Field using reflection. Which of the following tests will correctly indicate whether one is dealing with an int or an Integer? Field f = ... Cl...
Donnettedonni asked 16/8, 2011 at 18:16

2

Is it valuable for using Integer i = NumberUtils.INTEGER_ONE instead of Integer i = 1? I don't know what happen behind auto boxing. Thanks
Esophagitis asked 1/8, 2011 at 9:13

3

Solved

One can use typeof to determine whether a value is primitive or boxed. Consider: typeof "foo"; // "string" typeof new String("foo"); // "object" In combination with Object.prototype.toString w...
Disincline asked 22/7, 2011 at 16:40

2

Solved

What i'm trying to achieve here is a straight value comparison of boxed primitive types. ((object)12).Equals((object)12); // Type match will result in a value comparison, ((object)12).Equals((obje...
Automaton asked 12/7, 2011 at 17:49

5

Solved

I expect there's one of two answers to this, either impossible or extremely simple and I've overlooked the obvious Google query. The underlying issue is that I have a generic object being passed i...
Bert asked 10/6, 2011 at 1:30

4

Solved

Are 2 and 3 boxing/unboxing examples? 1) The documentation example: int i = 123; object iBoxed = i; i = (int) iBoxed; 2: Is the boxing/unboxing as well? int i = 123; object iBoxed = i; i = In...
Scully asked 6/6, 2011 at 8:11

5

Solved

Today I stumbled upon an interesting bug I wrote. I have a set of properties which can be set through a general setter. These properties can be value types or reference types. public void SetValue...
Runofthemine asked 1/6, 2011 at 17:6

3

Solved

I this MSDN Magazine article, the author states (emphasis mine): Note that boxing always creates a new object and copies the unboxed value's bits to the object. On the other hand, unboxing si...
Handmaiden asked 5/6, 2010 at 0:53

3

Solved

Is there a way to convert a boxed two-dimensional array to a two-dimensional string array in one step using C#/.NET Framework 4.0? using ( MSExcel.Application app = MSExcel.Application.CreateAppli...
Riggs asked 19/5, 2011 at 22:48

© 2022 - 2024 — McMap. All rights reserved.