相关疑难解决方法(0)

为什么可变结构"邪恶"?

在这里讨论了SO之后,我已经多次读过可变结构是"邪恶"的评论(就像这个问题的答案一样).

C#中可变性和结构的实际问题是什么?

c# struct mutable immutability

470
推荐指数
15
解决办法
7万
查看次数

为什么ValueType.GetHashCode()实现得像?

ValueType.cs

**Action: Our algorithm for returning the hashcode is a little bit complex. We look 
**        for the first non-static field and get it's hashcode.  If the type has no 
**        non-static fields, we return the hashcode of the type. We can't take the
**        hashcode of a static member because if that member is of the same type as 
**        the original type, we'll end up in an infinite loop.

今天当我使用KeyValuePair作为字典中的键(它存储了xml属性名称(枚举)和它的值(字符串))时,我被它咬了,并期望它根据其所有字段计算它的哈希码,但根据实施情况,它只考虑了关键部分.

示例(来自Linqpad的c/p):

void Main()
{
    var kvp1 = …
Run Code Online (Sandbox Code Playgroud)

c# gethashcode

23
推荐指数
3
解决办法
7741
查看次数

标签 统计

c# ×2

gethashcode ×1

immutability ×1

mutable ×1

struct ×1