我已经读过这个问题,为什么它不可能,但没有找到问题的解决方案.
我想从.NET中检索一个项目HashSet<T>.我正在寻找一种具有此签名的方法:
/// <summary>
/// Determines if this set contains an item equal to <paramref name="item"/>,
/// according to the comparison mechanism that was used when the set was created.
/// The set is not changed. If the set does contain an item equal to
/// <paramref name="item"/>, then the item from the set is returned.
/// </summary>
bool TryGetItem<T>(T item, out T foundItem);
Run Code Online (Sandbox Code Playgroud)
使用这种方法搜索集合的项目将是O(1).从a中检索项目的唯一方法HashSet<T>是枚举所有O(n)项.
除了自己制作HashSet<T>或使用之外,我还没有找到解决这个问题的方法Dictionary<K, V>.还有其他想法吗?
注意:
我不想检查是否HashSet<T> …
在我的C#应用程序中,我想启动默认图像编辑器来编辑图像.
当我使用System.Diagnostics.Process.Start("C:\\image.png")它时,使用Windows Photo Viewer打开图像文件.
当我在Windows资源管理器中右键单击图像文件时,会出现一个"编辑"菜单项,它启动Microsoft Paint(默认情况下).我想在我的应用程序中执行相同的操作(即使用默认图像编辑器打开文件).
我不想通过硬编码MS Paint Process.Start("mspaint.exe C:\\image.png").我更喜欢使用用户设置的默认图像编辑程序(可能与MS Paint不同).
有没有办法做到这一点?
谢谢弗兰克