English 中文(简体)
阵列/名单长度和架设的 has形码是否得到改观?
原标题:Are array/list lengths and string hashcodes memoized?
  • 时间:2012-01-12 23:01:24
  •  标签:
  • c#

是否有任何人知道在NET(4.0,如果是的话)中,一个阵列的租赁财产,或一个<代码>List<T>在计算之后储存,直到该阵列/名单发生变化?

我问,由于一个创纪录的联系方案Im在运作上已经非常复杂,而且如果我能够帮助,我就不要在事情上加上另一个O(n)。

同样,即时系统的散射编码。 • 努力改造? 看一看它,我可以看到<代码>。 List<T> has a private _size member that could 无论在哪里,数字都有其价值,但我看不到任何东西可以表明它们存放在任何地方。

我可以看一看大小与速度的权衡,但任何人都能够告诉我,是否有支持的领域可以控制这些? 例如,由于在C#中,插图是不可调用的,因此首次计算散列码是明智之举。 CanHashCode被称作,只是将其储存供日后使用?

最佳回答

采用<代码>List<T>.Count:

public int Count
{
  get
  {
    return this._size;
  }
}

I m not sure about Array.Length. The code for it is:

public int Length 
{ 
    [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), 
    SecuritySafeCritical, MethodImpl(MethodImplOptions.InternalCall)] 
    get; 
}
问题回答

http://msdn.microsoft.com/en-us/library/6sh2ey19(v=VS.100).aspx“rel=“nofollow” http://msdn.microsoft.com/en-us/library/6sh2ey19(v=VS.100)。

The List class is the generic equivalent of the ArrayList class. It implements the IList generic interface using an array whose size is dynamically increased as required.

这表明,租赁财产在任何时候都知道,无需计算。

.NET Reference Code ,我看着清单。 它具有可变性。 因此,凡添加或删除某一项内容时,均应加进或缩小规模。 因此,它并不真正计算,而且总是储存在一个变数中。





相关问题
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. ...

热门标签