Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 已排序的列表项_C#_Visual Studio 2010_Sortedlist - Fatal编程技术网

C# 已排序的列表项

C# 已排序的列表项,c#,visual-studio-2010,sortedlist,C#,Visual Studio 2010,Sortedlist,是否可以使用相同的值将项目添加到排序列表中,因为当我尝试这样做时,会显示一个错误: 具有相同密钥的条目已存在。 如果可能的话,怎么做?不,不可能。钥匙必须是唯一的。不,这是不可能的。键必须是唯一的。键应该是唯一的。请参见MSDN中的内容 ArgumentException - An element with the specified key already exists in the SortedList object. 密钥应该是唯一的。请参见MSDN中的内容 ArgumentExce

是否可以使用相同的值将项目添加到排序列表中,因为当我尝试这样做时,会显示一个错误: 具有相同密钥的条目已存在。
如果可能的话,怎么做?

不,不可能。钥匙必须是唯一的。

不,这是不可能的。键必须是唯一的。

键应该是唯一的。请参见MSDN中的内容

ArgumentException   - An element with the specified key already exists in the SortedList object.

密钥应该是唯一的。请参见MSDN中的内容

ArgumentException   - An element with the specified key already exists in the SortedList object.

无法*添加其他用户所述的重复密钥

在c语言中,您可以使用Lookup类,它允许使用同一个键存储多个值

见:


*这是可能的,请参阅注释,但仅通过定义一个比较器,该比较器从不为相等的项返回相等值,这在我看来是一个非常糟糕的主意。

不可能*添加其他用户所述的重复键

在c语言中,您可以使用Lookup类,它允许使用同一个键存储多个值

见:


*这是可能的,请参阅注释,但只能通过定义一个比较器,该比较器从不为相等的项返回相等值,这在我看来是一个非常糟糕的主意。

定义一个实现IComparer的类。实例化SortedList时,传入类的实例。签出。

定义一个实现IComparer的类。实例化SortedList时,传入类的实例。退房。

这是可能的。查看一个类似的问题,该解决方案打破了容器的一个先决条件,即两个相等的键将返回相等,正如评论者所指出的,这将引入一系列其他问题。最好使用这种方式使用的容器。这意味着我会更新我的答案。很好。卡斯特巴克斯回答中的评论揭示了一些可能的错误。查看一个类似的问题,该解决方案打破了容器的一个先决条件,即两个相等的键将返回相等,正如评论者所指出的,这将引入一系列其他问题。最好使用这种方式使用的容器。这意味着我会更新我的答案。很好。卡斯特巴克斯回答中的评论揭示了一些可能的错误。用卡斯特巴克斯的答案来看一个类似的问题有一些警告。阅读评论,这是可能的。用卡斯特巴克斯的答案来看一个类似的问题有一些警告。阅读评论,这是可能的。看看类似的问题,这是可能的。请参阅类似问题的可能副本