我想创建一个包含整数元素和日期时间元素的多维数组。我希望能够对日期时间元素进行排序,并根据排序的日期时间元素获取整数元素。有没有办法在 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/