小编Rah*_*abi的帖子

为什么在重写Equals方法时重写GetHashCode很重要?

鉴于以下课程

public class Foo
{
    public int FooId { get; set; }
    public string FooName { get; set; }

    public override bool Equals(object obj)
    {
        Foo fooItem = obj as Foo;

        if (fooItem == null) 
        {
           return false;
        }

        return fooItem.FooId == this.FooId;
    }

    public override int GetHashCode()
    {
        // Which is preferred?

        return base.GetHashCode();

        //return this.FooId.GetHashCode();
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经覆盖了该Equals方法,因为它Foo代表了Foos表的一行.哪个是覆盖的首选方法GetHashCode

覆盖为什么重要GetHashCode

c# overriding hashcode

1371
推荐指数
13
解决办法
35万
查看次数

为什么简单的Go应用会消耗大量内存

这是一个非常简单的应用程序:

package main
import "fmt"
func main() {

    for i:= 0; i < 100000; i++ {
        go func (){
            fmt.Println("hello message.")
        }()
    }

    fmt.Scanln()
    fmt.Println("done")
}
Run Code Online (Sandbox Code Playgroud)

在Windows上运行应用程序后,并查看Windows任务管理器,我看到了以下状态:

进入应用状态

有人可以说为什么?

string memory-leaks go goroutine

-3
推荐指数
1
解决办法
113
查看次数

标签 统计

c# ×1

go ×1

goroutine ×1

hashcode ×1

memory-leaks ×1

overriding ×1

string ×1