English 中文(简体)
该系统。 射线在价值类型上进行盒子吗?
原标题:Does System.Array perform boxing on value types or not?

我最近做了一些粗略的表演,测量如下:<代码>List<> vs <代码>[>,用于一系列小型结构。 系统。 阿雷拉似乎 win倒,因此我也这样做。

这只是我刚刚开始的。 射线含有物体类型,因此肯定用结构填充它会导致箱子出现吗?

然而,MSDN系统入册。 Array:

In the .NET Framework version 2.0, the Array class implements the System.Collections.Generic.IList<T>, System.Collections.Generic.ICollection<T>, and System.Collections.Generic.IEnumerable<T> generic interfaces. The implementations are provided to arrays at run time, and therefore are not visible to the documentation build tools. As a result, the generic interfaces do not appear in the declaration syntax for the Array class, and there are no reference topics for interface members that are accessible only by casting an array to the generic interface type (explicit interface implementations).

这是否意味着箱子在全部之后不会发生? (并将解释我的业绩成果)

最佳回答

No using an array does not box if you use the indexer notation. e.g.

new int[2];
x=[1]=3;

与以下国际空间法研究所的对应数据(指从其他几套法典中得出的线数不相干)

IL_0011: ldc.i4.2
IL_0012: newarr System.Int32
IL_0017: stfld Int32[] x
IL_001c: ldarg.0
IL_001d: ldfld Int32[] x
IL_0022: ldc.i4.1
IL_0023: ldc.i4.3
IL_0024: stelem.i4

For languages that cannot use the indexer (and I don t really know if they exist or not) 2 other methods are created at compile time for Arrays.

该法规定了这些公共方法:

public int Get(int index)
public void Set(int index,int value)

这些方法要么没有盒子,要么通常无法通过C#.(不要问我为什么是公开的)。 你们可以通过使用国际空间法中心或为其设立代表来执行这些文书。 由于你被迫使用这些方法,他们正在 slower。

The stelem.* and ldelem.* family is used to address storing to a persistent category. 通常使用通用代码的序号如下:constraining/code>或 使用<代码>T[]。 www.un.org/spanish/ga/president 通常类型不检查。 例如,使用<代码>stelem.i4比使用stelem.any Int<32/code>更快,除非您先贴在上>。 否则,它就会进行一类检查。

如今,这种类型的检查是,在价值类型的阵列中,完全没有使用。

由于操作时间产生一种从零开始的内层阵列(即所谓的SZ-array或病媒类型),因此,它们为本地人所知。

There are a family of il op codes for them: newarr,stelem.*,ldelem.*,ldlen etc.

The List<T> category used a T[] for its supporting Store in the microsoft implementation of the BCL. <代码>List<T>不是箱子。 不管使用清单或阵列,你都把事情储存在一个阵列。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...