相关疑难解决方法(0)

.NET唯一对象标识符

有没有办法获取实例的唯一标识符?

GetHashCode()对于指向同一实例的两个引用是相同的.但是,两个不同的实例可以(很容易)获得相同的哈希码:

Hashtable hashCodesSeen = new Hashtable();
LinkedList<object> l = new LinkedList<object>();
int n = 0;
while (true)
{
    object o = new object();
    // Remember objects so that they don't get collected.
    // This does not make any difference though :(
    l.AddFirst(o);
    int hashCode = o.GetHashCode();
    n++;
    if (hashCodesSeen.ContainsKey(hashCode))
    {
        // Same hashCode seen twice for DIFFERENT objects (n is as low as 5322).
        Console.WriteLine("Hashcode seen twice: " + n + " (" + hashCode + ")");
        break; …
Run Code Online (Sandbox Code Playgroud)

c# unique hashcode gethashcode

113
推荐指数
7
解决办法
11万
查看次数

WPF TextBlock元素和Label控件之间有什么区别?

视觉上,以下两个片段都生成相同的UI.那么为什么有2个控件..
Snippet1

<TextBlock>Name:</TextBlock>
<TextBox Name="nameTextBox" />
Run Code Online (Sandbox Code Playgroud)

Snippet2

<Label>Name:</Label>
<TextBox Name="nameTextBox" />
Run Code Online (Sandbox Code Playgroud)

(好吧,我自己会回答这个问题......认为这是我今天从编程WPF学到的一个有用的小问题)

wpf

102
推荐指数
2
解决办法
6万
查看次数

有没有办法在不使用XAML的情况下设置对象的AutomationID?

我需要自动化Winform应用程序.如何设置AutomationID(或AutomationName)像本文中的XAML 一样?

从这个堆栈溢出文章看,答案似乎是否定,除非我将应用程序切换到WPF应用程序(因此我可以使用XAML来定义控件).

我尝试过这种天真的方法:

  AutomationElement formAutomation = AutomationElement.FromHandle(this.Handle);
  formAutomation.Current.Name = "SandboxResponseDialogName";
  formAutomation.Current.ClassName = "SandboxResponseDialogClassName";
  formAutomation.Current.AutomationId = "SandboxResponseDialogID;
Run Code Online (Sandbox Code Playgroud)

但是在控制构造函数的这一点上,这些Automation属性只有getter; 没有二传手.

c# ui-automation winforms

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×2

gethashcode ×1

hashcode ×1

ui-automation ×1

unique ×1

winforms ×1

wpf ×1