c# - C# 中具有多种数据类型的多维数组?

标签 c# arrays multidimensional-array

我想创建一个包含整数元素和日期时间元素的多维数组。我希望能够对日期时间元素进行排序,并根据排序的日期时间元素获取整数元素。有没有办法在 C# 中使用数组来做到这一点,或者我应该使用更像数据表的东西?

最佳答案

要保留 interegs 和 DateTimes,请使用通用的 System.Collections。Dictionary<DateTime, int>>

要保持顺序,请使用 System.Collections.Specialized.OrderedDictionary。请参阅 MSDN 中的示例 ( here )。

// Creates and initializes a OrderedDictionary.
OrderedDictionary myOrderedDictionary = new OrderedDictionary();
myOrderedDictionary.Add("testKey1", "testValue1");
myOrderedDictionary.Add("testKey2", "testValue2");
myOrderedDictionary.Add("keyToDelete", "valueToDelete");
myOrderedDictionary.Add("testKey3", "testValue3");

ICollection keyCollection = myOrderedDictionary.Keys;
ICollection valueCollection = myOrderedDictionary.Values;

// Display the contents using the key and value collections
DisplayContents(keyCollection, valueCollection, myOrderedDictionary.Count);

关于c# - C# 中具有多种数据类型的多维数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1882120/

相关文章:

c# - C#:在列表中查找类字段

c# - .NET Framework 依赖关系树

c - 用于非均匀大小超球体中最近邻搜索的快速空间数据结构

javascript - 简单的无名 json 数组转换为映射的 JS 或 PHP 数组

c# - 我可以使用 Visual Studio 的数据源配置向导连接到 YouTube api 吗?

c# - double 在特殊情况下丢失数字(也没有 int 转换)

java - 在 Java 中为字节数组实现缓冲区

C++ 控制台问题

php - 如何将数组键值转换为百分比

r - 如何动态索引多维R数组?