本文整理汇总了C#中Object.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Object.GetHashCode方法的具体用法?C# Object.GetHashCode怎么用?C# Object.GetHashCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object
的用法示例。
在下文中一共展示了Object.GetHashCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Go
public static void Go() {
Console.WriteLine(); // Call a static method
Object o = new Object();
o.GetHashCode(); // Call a virtual instance method
o.GetType(); // Call a nonvirtual instance method
}
示例2: ArgumentNullException
int IEqualityComparer.GetHashCode ( Object obj ) {
int hashCode;
XPathNavigator nav;
XPathDocumentNavigator xpdocNav;
if (obj == null) {
throw new ArgumentNullException("obj");
}
else if ( null != (xpdocNav = obj as XPathDocumentNavigator) ) {
hashCode = xpdocNav.GetPositionHashCode();
}
else if( null != (nav = obj as XPathNavigator) ) {
Object underlyingObject = nav.UnderlyingObject;
if (underlyingObject != null) {
hashCode = underlyingObject.GetHashCode();
}
else {
hashCode = (int)nav.NodeType;
hashCode ^= nav.LocalName.GetHashCode();
hashCode ^= nav.Prefix.GetHashCode();
hashCode ^= nav.NamespaceURI.GetHashCode();
}
}
else {
hashCode = obj.GetHashCode();
}
return hashCode;
}
示例3: GetHashCode
public virtual int GetHashCode(Object o) {
String obj = o as string;
if (obj == null) {
return o.GetHashCode();
}
return BackCompatibleStringComparer.GetHashCode(obj);
}
示例4: GetHashCode
public int GetHashCode(Object obj) {
if( obj == null) {
throw new ArgumentNullException("obj");
}
if (_hcp != null)
return _hcp.GetHashCode(obj);
return obj.GetHashCode();
}
示例5: GetHashCode
public int GetHashCode(Object obj) {
if( obj == null) {
throw new ArgumentNullException(nameof(obj));
}
Contract.EndContractBlock();
if (_hcp != null)
return _hcp.GetHashCode(obj);
return obj.GetHashCode();
}
示例6: GetHash
// Internal method to get the hash code for an Object. This will call
// GetHashCode() on each object if you haven't provided an IHashCodeProvider
// instance. Otherwise, it calls hcp.GetHashCode(obj).
protected virtual int GetHash(Object key)
{
if (_keycomparer != null)
return _keycomparer.GetHashCode(key);
return key.GetHashCode();
}
示例7: HashableSerializedProperty
/// <summary>
/// Initializes a new instance of the
/// <see cref="PropertyBackingFieldDrawer+HashableSerializedProperty"/> struct.
/// </summary>
/// <param name="path">Path.</param>
/// <param name="target">Target.</param>
public HashableSerializedProperty(string path, Object target) : this()
{
m_PropertyPath = path;
m_TargetObject = target;
// store the hash upon construction, in case the object is killed later
m_Hash = ObjectX.GenerateHashCode(m_PropertyPath.GetHashCode(), m_TargetObject.GetHashCode());
}
示例8: TestHelpersGetObjectValue
// Test "RuntimeHelpers.GetObjectValue".
public void TestHelpersGetObjectValue()
{
// Null's value is itself.
AssertNull("GetObjectValue (1)",
RuntimeHelpers.GetObjectValue(null));
// Object references map to themselves.
Object obj = new Object();
AssertSame("GetObjectValue (2)", obj,
RuntimeHelpers.GetObjectValue(obj));
// Immutable primitive types map to themselves.
obj = (Object)3;
AssertSame("GetObjectValue (3)", obj,
RuntimeHelpers.GetObjectValue(obj));
obj = (Object)(AttributeTargets.Assembly);
AssertSame("GetObjectValue (4)", obj,
RuntimeHelpers.GetObjectValue(obj));
// Other value types are cloned.
GetObjectValueTest t = new GetObjectValueTest(3);
obj = (Object)t;
Object clone = RuntimeHelpers.GetObjectValue(obj);
AssertNotSame("GetObjectValue (5)", obj, clone);
AssertEquals("GetObjectValue (6)",
((GetObjectValueTest)obj).value,
((GetObjectValueTest)clone).value);
obj.GetHashCode(); // side-effect value.
AssertEquals("GetObjectValue (7)", 4,
((GetObjectValueTest)obj).value);
AssertEquals("GetObjectValue (8)", 3,
((GetObjectValueTest)clone).value);
}
示例9:
int IEqualityComparer.GetHashCode(Object obj)
{
return obj.GetHashCode();
}
示例10: GetHashCode
public Int32 GetHashCode(Object obj1)
{
return obj1.GetHashCode();
}
示例11: Equals
/**
* <inheritdoc />
*/
public override bool Equals(Object obj)
{
CIE1960 ucsObj = obj as CIE1960;
if (ucsObj == this) {
return true;
}
if (ucsObj == null || GetHashCode () != obj.GetHashCode ()) {
return false;
}
return (U == ucsObj.U && V == ucsObj.V && W == ucsObj.W);
}
示例12: GetHashCode
// Get the hash code for an object.
public int GetHashCode(Object obj)
{
if(obj != null)
{
return obj.GetHashCode();
}
else
{
return 0;
}
}
示例13: GetHash
protected virtual int GetHash(Object key)
{
//获取哈希码
return key.GetHashCode();
}
示例14: hash
private int hash(Object obj)
{
return obj.GetHashCode()/*System.identityHashCode(obj)*/ & 0x7FFFFFFF;
}
示例15: test_0_intrins_object_gethashcode
public static int test_0_intrins_object_gethashcode () {
object o = new Object ();
return (o.GetHashCode () == o.GetHashCode ()) ? 0 : 1;
}