Reback 2011.10.25
Since i forget my password, i can't login in nearly one month. Why so long ? because in company, other mail box is forbidden. so i should use my homenetwork, but i has no network at home.
lately, i learn c# now.colleague advie a tool named ILSPY, it's a decompile tool, can see some code about how to complete core function. it's very useful. the address url as follow: http://wiki.sharpdevelop.net/ILSpy.ashx
here give two example:
first is about Dictionary
When we add a new pair <key, value> to a Dictionary , what will be compare with key ?
ILSpy ‘s result and my simple comment , any question link me.
//hash code
int num = this.comparer.GetHashCode(key) & 2147483647;
int num2 = num % this.buckets.Length;
for (int i = this.buckets[num2]; i >= 0; i = this.entries[i].next)
{
// first judge hashcode , then use equals judge, as default , equals use RefferenceEquals, just the address of memory. So it is
if (this.entries[i].hashCode == num && this.comparer.Equals(this.entries[i].key, key))
{
if (add)
{
ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_AddingDuplicate);
}
this.entries[i].value = value;
this.version++;
return;
}
}
/////////////////////
second is Foreach
private bool MoveNextRare()
{
//use foreach, version is a key step
if (this.version != this.list._version)
{
ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
}
this.index = this.list._size + 1;
this.current = default(T);
return false;
}