本文整理汇总了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);
}
}
}
示例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());
}
}
示例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());
}
}
示例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());
}
}
示例5: Equals
public override bool Equals(Object o)
{
int hashPropio = GetHashCode();
int hashParametro = o.GetHashCode();
return hashPropio == hashParametro;
}
示例6: Equals
public override bool Equals(Object obj)
{
if (obj.GetHashCode() == (Int32)key_)
return true;
return false;
}
示例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;
}
示例8: Add
public HashCodeHelper Add(Object obj)
{
unchecked
{
Hash = Hash * 31 + obj.GetHashCode();
}
return this;
}
示例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
}
}
示例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
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}
示例15: Get
public Object Get(Object key)
{
int hash = key.GetHashCode();
int lookup = GetLookup(key, hash);
if (lookup != -1)
{
return objectValueTable[lookup];
}
return null;
}