C#相当于C ++向量,具有连续内存? [英] C# equivalent of C++ vector, with contiguous memory?

查看:128
本文介绍了C#相当于C ++向量,具有连续内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++向量的C#等价是什么?

What's the C# equivalent of C++ vector?

我正在搜索此功能:

要拥有一个没有性能的连续存储内存的动态数组访问与标准数组的罚分。

To have a dynamic array of contiguously stored memory that has no performance penalty for access vs. standard arrays.

我正在搜索,他们说 .NET等价于C ++中的向量是ArrayList ,所以:

I was searching and they say .NET equivalent to the vector in C++ is the ArrayList, so:

Do ArrayList有连续的内存特性吗?

Do ArrayList have that contiguous memory feature?

推荐答案

您可以使用 列表< T> ,并且 T 是值类型时,它将分配在连续内存中,如果 T 是参考类型。

You could use a List<T> and when T is a value type it will be allocated in contiguous memory which would not be the case if T is a reference type.

示例:

List<int> integers = new List<int>();
integers.Add(1);
integers.Add(4);
integers.Add(7);

int someElement = integers[1];

这篇关于C#相当于C ++向量,具有连续内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆