如何在List C中获取唯一值# [英] How to get unique values in List C#

查看:69
本文介绍了如何在List C中获取唯一值#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我需要维护一个唯一的列表来维护已打开的订单列表。



如果我点击datagridview中的一行,orderid作为参数传递给构造函数。

这样打开一个新表单。当我点击一行时,一个表格的新实例打开。



现在我的问题是,如果我点击一行五次,则会打开五个相同的订单。



我试图在Cell点击事件的第一行保留一个标志,但我仍然打开了多个订单。



现在我正在尝试的是我需要一个唯一的列表类型,例如HashSet,它只支持唯一值。



我将orderid添加到hashset。一旦它获得另一个相同的orderid,它就会产生异常,因此它不会打开多个订单。但我面临的挑战是我使用 .NET 2.0 版本。



那么如何解决这个问题问题。

帮助感谢。

Hi,
I need to Maintain a unique list to maintain list of opened orders.

If I click on a row in datagridview an orderid is passed as a parameter to constructor.
Thus opening a new form. when I click on a row a new instance of a form open.

Now My question is that if I click a row five time five same orders opens.

I tried keeping a flag in the first line of the Cell click event but still I am getting multiple orders opened.

Now what I am trying is that I need a unique list type such as HashSet which support only unique values.

I will add the orderid to hashset. once it get another same orderid it produces exception thus it wont open multiple order. But the challenge for me is that I am using .NET 2.0 version.

So how to resolve this issue.
Help Appreciated.

推荐答案

你总是可以检查你的对象集...就像打开一个新实例之前你可以在打开表单的可用列表,如果找到,请激活它或将其带到工作前面:))
you can always check your object collection... like before opening a new instance you can check within the available list of opened forms and if you found one, activate it or bring it to front for work :)


我建​​议使用词典 [ ^ ]。它可以按照您的工作方式工作。不要让你两次输入相同的值。



正如Rob Philopott所说,你可以使用列表 [ ^ ],它提供检查是否已添加值的功能。



最后,我建议检查打开订单表单的函数/方法。
I'd suggest to use Dictionary[^]. It works as you wish to work. Don't let you to enter the same value twice.

As Rob Philopott mentioned, you can use List[^] too, which provides functionality to check if value has been already added.

Finally, i'd suggest to check function/method which opens Order form.


这篇关于如何在List C中获取唯一值#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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