当前位置: 首页>>代码示例>>C#>>正文


C# Object.GetHashCode方法代码示例

本文整理汇总了C#中System.Object.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Object.GetHashCode方法的具体用法?C# Object.GetHashCode怎么用?C# Object.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Object的用法示例。


在下文中一共展示了Object.GetHashCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssertEqualsHashCode

 public static void AssertEqualsHashCode(Object o, Object o2)
 {
     if (o.Equals(o2)) {
     if (!o2.Equals(o)) {
       Assert.Fail(
       String.Empty + o + " equals " + o2 + " but not vice versa");
     }
     // Test for the guarantee that equal objects
     // must have equal hash codes
     if (o2.GetHashCode() != o.GetHashCode()) {
       // Don't use Assert.AreEqual directly because it has
       // quite a lot of overhead
       Assert.Fail(
       String.Empty + o + " and " + o2 + " don't have equal hash codes");
     }
       } else {
     if (o2.Equals(o)) {
       Assert.Fail(String.Empty + o + " does not equal " + o2 +
     " but not vice versa");
     }
     // At least check that GetHashCode doesn't throw
     try {
      o.GetHashCode();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
     }
     try {
      o2.GetHashCode();
     } catch (Exception ex) {
     Assert.Fail(ex.ToString());
     throw new InvalidOperationException(String.Empty, ex);
     }
       }
 }
开发者ID:peteroupc,项目名称:MailLib,代码行数:35,代码来源:TestCommon.cs

示例2: removeListeners

 public void removeListeners(Object context)
 {
     if(contextBinder.ContainsKey(context.GetHashCode())){
         contextBinder[context.GetHashCode()].ForEach((listener) => {
             foreach(Object key in customListeners.Keys){
                 if (customListeners[key].Contains(listener)) {
                     customListeners[key].Remove(listener);
                 }
             }
         });
         contextBinder.Remove(context.GetHashCode());
     }
 }
开发者ID:pedroassis,项目名称:SuperTrunfo,代码行数:13,代码来源:GameObserver.cs

示例3: checkEqualsAndHashCodeMethods

        private static void checkEqualsAndHashCodeMethods(Object lhs, Object rhs,
                                                          bool expectedResult)
        {
            if ((lhs == null) && (rhs == null))
            {
                assertTrue(
                    "Your check is dubious...why would you expect null != null?",
                    expectedResult);
                return;
            }

            if ((lhs == null) || (rhs == null))
            {
                assertFalse(
                    "Your check is dubious...why would you expect an object "
                    + "to be equal to null?", expectedResult);
            }

            if (lhs != null)
            {
                assertEquals(expectedResult, lhs.Equals(rhs));
            }
            if (rhs != null)
            {
                assertEquals(expectedResult, rhs.Equals(lhs));
            }

            if (expectedResult)
            {
                var hashMessage =
                    "hashCode() values for equal objects should be the same";
                assertTrue(hashMessage, lhs.GetHashCode() == rhs.GetHashCode());
            }
        }
开发者ID:ishnayder,项目名称:s2-geometry-library-csharp,代码行数:34,代码来源:S2PolylineTest.cs

示例4: Verify

		/// <summary>
		/// Calls Verify() with the object and it's type.
		/// </summary>
		/// <param name="verifiableObject">Object to verify</param>
		public static void Verify(Object verifiableObject) 
		{
			if ( !_verifiedObjects.Contains( verifiableObject.GetHashCode() ) )
			{
				verify(verifiableObject, verifiableObject.GetType());
			}
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:11,代码来源:Verifier.cs

示例5: Equals

        public override bool Equals(Object o) 
        {
            int hashPropio = GetHashCode();
            int hashParametro = o.GetHashCode();

            return hashPropio == hashParametro;
        }
开发者ID:SantiMA10,项目名称:2ndo,代码行数:7,代码来源:Persona.cs

示例6: Equals

        public override bool Equals(Object obj)
        {
            if (obj.GetHashCode() == (Int32)key_)
                return true;

            return false;
        }
开发者ID:sunglim,项目名称:CheckNewfile,代码行数:7,代码来源:AcceleratorKey.cs

示例7: CombineHashCodes

 /// <summary>
 /// Does a quick and simple combination of the Hash Codes of two Objects
 /// </summary>
 /// <param name="x">First Object</param>
 /// <param name="y">Second Object</param>
 /// <returns></returns>
 public static int CombineHashCodes(Object x, Object y)
 {
     int hash = 17;
     hash = hash * 31 + x.GetHashCode();
     hash = hash * 31 + y.GetHashCode();
     return hash;
 }
开发者ID:jmahmud,项目名称:RDFer,代码行数:13,代码来源:Tools.cs

示例8: Add

 public HashCodeHelper Add(Object obj)
 {
     unchecked
     {
         Hash = Hash * 31 + obj.GetHashCode();
     }
     return this;
 }
开发者ID:jmht,项目名称:QueryParser,代码行数:8,代码来源:HashCodeHelper.cs

示例9: UnmarshaledObject

 // Notifies a handler that an object has been unmarshaled.
 public void UnmarshaledObject(Object obj, ObjRef or)
 {
     if (obj.GetType() != typeof(AppDomain))
         Trace.WriteLine(string.Format("Tangra Addins: Unmarshaled instance of {0} ({1} HashCode:{2})", or.TypeInfo != null ? or.TypeInfo.TypeName : obj.GetType().ToString(), or.URI != null ? or.URI.ToString() : "N/A", obj.GetHashCode().ToString()));
     else
     {
         // Not interested in AppDomain marshalling
     }
 }
开发者ID:hpavlov,项目名称:tangra3,代码行数:10,代码来源:AddinTrackingHandler.cs

示例10: DisconnectedObject

 // Notifies a handler that an object has been disconnected.
 public void DisconnectedObject(Object obj)
 {
     if (obj.GetType() != typeof(AppDomain))
         Trace.WriteLine(string.Format("Tangra Addins: Disconnected instance of {0} (HashCode:{1})", obj.GetType().ToString(), obj.GetHashCode().ToString()));
     else
     {
         // Not interested in AppDomain marshalling
     }
 }
开发者ID:hpavlov,项目名称:tangra3,代码行数:10,代码来源:AddinTrackingHandler.cs

示例11: UnregisterEventListener

 internal void UnregisterEventListener(Enum pEvent, Object pListenerParent)
 {
     if (mEventDictionnary.ContainsKey(pEvent))
     {
         EventListener eventListener = mEventDictionnary[pEvent].FirstOrDefault((currentEventListener) => { return currentEventListener.ListenerHashCode == pListenerParent.GetHashCode(); });
         mEventDictionnary[pEvent].Remove(eventListener);
         UnregisterEventListener(eventListener);
     }
 }
开发者ID:ysucae,项目名称:Balloune,代码行数:9,代码来源:EventDispatcher.cs

示例12: GetHashCode

        private static int GetHashCode(Object Instance,IntPtr l)
        {
            // get method arguments

                  // call method
                  Int32 methodRetVar = Instance.GetHashCode();

                  LuaApi.lua_pushnumber(l,methodRetVar);
                  return 1;
        }
开发者ID:huiguochen,项目名称:Lua4Net,代码行数:10,代码来源:Object.cs

示例13: GetHashCode

        public int GetHashCode(Object obj) {
            if (obj == null) return 0;

            IStructuralEquatable seObj = obj as IStructuralEquatable;

            if (seObj != null) {
                return seObj.GetHashCode(this);
            }

            return obj.GetHashCode();
        }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:11,代码来源:StructuralComparisons.cs

示例14: Equals

 public override bool Equals(Object o)
 {
     if (o == null)
     {
         return false;
     }
     if (this.GetType() == o.GetType())
     {
         return o.GetHashCode() == this.GetHashCode();
     }
     return false;
 }
开发者ID:rafaelo4n,项目名称:Progas.Portal,代码行数:12,代码来源:ClienteCondicaoLiberada.cs

示例15: Get

        public Object Get(Object key)
        {
            int hash = key.GetHashCode();
            int lookup = GetLookup(key, hash);

            if (lookup != -1)
            {
                return objectValueTable[lookup];
            }

            return null;
        }
开发者ID:jihadbird,项目名称:firespider,代码行数:12,代码来源:HashMap.cs


注:本文中的System.Object.GetHashCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。