我是初学者.NET开发人员。我正在尝试了解基本内容,以便更好地了解代码中的实际情况。
是否可以获取静态对象的哈希码?在任何情况下都可能有必要吗?
代码如下:
class DynamicClass
{
//Class body
}
static class StaticClass
{
//Class body
}
class program
{
static void Main()
{
//Getting hashcode of DynamicClass object
DynamicClass x = new DynamicClass();
Console.WriteLine(x.GetHashCode());
//Getting hashcode of StaticClass object
//Since the class is static i can't instantiate it, so i am
//trying to call GetHashCode method right on the object
Console.WriteLine(StaticClass.GetHashCode()); // ERROR CS120
}
}
谢谢!