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


C# Object.Equals方法代码示例

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


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

示例1: JScriptIn

 //"x in y" should return true whenever "for (var z in y) if (z === x) return true" returns true
 public static bool JScriptIn(Object v1, Object v2){
   bool result = false;
   if (v2 is ScriptObject)
     return !(((ScriptObject)v2).GetMemberValue(Convert.ToString(v1)) is Missing);
   else if (v2 is Array){
     Array arr = (Array)v2;
     double d = Convert.ToNumber(v1);
     int i = (int)d;
     return d == i && arr.GetLowerBound(0) <= i && i <= arr.GetUpperBound(0);
   }else if (v2 is IEnumerable){
     if (v1 == null) return false;
     //Do not enumerate when a direct lookup is available
     if (v2 is IDictionary)
       return ((IDictionary)v2).Contains(v1);
     if (v2 is IExpando){
       MemberInfo[] members = ((IReflect)v2).GetMember(Convert.ToString(v1), BindingFlags.Instance|BindingFlags.DeclaredOnly|BindingFlags.Public);
       return members.Length > 0;
     }
     IEnumerator enu = ((IEnumerable)v2).GetEnumerator();
     while (!result && enu.MoveNext())
       if (v1.Equals(enu.Current)) return true;
   }else if (v2 is IEnumerator){
     if (v1 == null) return false;          
     IEnumerator enu = (IEnumerator)v2;
     while (!result && enu.MoveNext())
       if (v1.Equals(enu.Current)) return true;
   }
   throw new JScriptException(JSError.ObjectExpected);
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:30,代码来源:in.cs

示例2: 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

示例3: getPatientName

 public String getPatientName(Object markerID)
 {
     if (markerID.Equals("PatientMarkerConfig.txt"))
         return "Smith, John";
     else if (markerID.Equals(2))
         return "Doe, Jane";
     return "No Patient";
 }
开发者ID:nmrabinovich,项目名称:MedAR,代码行数:8,代码来源:PatientModule.cs

示例4: Convert

 public object Convert(Object value , Type targetType , Object parameter , System.Globalization.CultureInfo culture)
 {
     if (value.Equals("儿童"))
     {
         return new SolidColorBrush(Colors.Yellow);
     }
     if (value.Equals("成人"))
     {
         return new SolidColorBrush(Colors.Orange);
     }
     else
         return new SolidColorBrush(Colors.Gray);
 }
开发者ID:zealoussnow,项目名称:OneCode,代码行数:13,代码来源:ColorConverter.cs

示例5: Main

        static void Main(string[] args)
        {
            Object o = new Object();
            Object p = new Object();
            Object q = o;

            Console.WriteLine(o.Equals(p));
            Console.WriteLine(o.Equals(q));

            Console.WriteLine(Object.Equals(p, q));

            Console.ReadKey();
        }
开发者ID:50minutos,项目名称:VS2010,代码行数:13,代码来源:Program.cs

示例6: AreObjectsEqual

        public static bool AreObjectsEqual(Object x, Object y)
        {
            if (x == y) 
                return true;

            if (x is ArrayList)
            {
                if (!(y is ArrayList))
                    return false;
                ArrayList a = x as ArrayList;
                ArrayList b = y as ArrayList;
                if (a.Count != b.Count)
                {
                    return false;
                }
                else
                {
                    for (int i=0; i < a.Count; ++i)
                    {
                        if (!AreObjectsEqual(a[i], b[i]))
                            return false;
                    }
                    return true;
                }
            }
            else
            {
                return x.Equals(y);
            }
        }
开发者ID:catb0t,项目名称:cat-language,代码行数:30,代码来源:CatBase.cs

示例7: AssertArgumentNotEquals

 protected void AssertArgumentNotEquals(Object anObject1, Object anObject2, String aMessage)
 {
     if (anObject1.Equals(anObject2))
     {
         throw new ArgumentException(aMessage);
     }
 }
开发者ID:jefferydalton,项目名称:FuelTracker---Archived,代码行数:7,代码来源:AssertionConcern.cs

示例8: 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

示例9: IsEquals

 public static void IsEquals(Object expectedValue, Object actualValue, string message)
 {
     if (actualValue.Equals(expectedValue))
         return;
     string s = message != null ? ": " + message : String.Empty;
     string format = String.Format("Expected {0} but encountered {1}{2}", expectedValue, actualValue, s);
     throw new AssertionFailedException(format);
 }
开发者ID:Walt-D-Cat,项目名称:NetTopologySuite,代码行数:8,代码来源:Assert.cs

示例10: assertEqual

 public virtual void assertEqual(Object result, Object expecting)
 {
     if (result == null && expecting != null)
     {
         throw new FailedAssertionException("expecting \"" + expecting + "\"; found null");
     }
     assertTrue(result.Equals(expecting), "expecting \"" + expecting + "\"; found \"" + result + "\"");
 }
开发者ID:david-mcneil,项目名称:stringtemplate,代码行数:8,代码来源:TestSuite.cs

示例11: AreEqual

 public static void AreEqual(Object a, Object b, string message, bool launchDebugger)
 {
     if (a.Equals(b) == false)
     {
         if (launchDebugger)
             DebugUtil.LaunchDebugger();
         throw new Exception(message + ", '" + a.ToString() + "' != '" + b.ToString() + "'");
     }
 }
开发者ID:boinst,项目名称:ColladaXna,代码行数:9,代码来源:DebugUtil.cs

示例12: Equals

 /// <include file='doc\Object.uex' path='docs/doc[@for="Object.Equals1"]/*' />
 public static bool Equals(Object objA, Object objB) {
     if (objA==objB) {
         return true;
     }
     if (objA==null || objB==null) {
         return false;
     }
     return objA.Equals(objB);
 }
开发者ID:ArildF,项目名称:masters,代码行数:10,代码来源:object.cs

示例13: Equals

		protected new bool Equals(Object o1, Object o2) {
			if (o1 == null) {
				return o2 == null;
			} else if (o2 == null) {
				return false;
			} else {
				return o1.Equals(o2);
			}
		}
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:9,代码来源:BaseEntity.cs

示例14: Equals

        public new bool Equals(Object x, Object y)
        {
            if (x != null)
            {
                var tObj = x as IStructuralEquatable;

                return tObj != null ? tObj.Equals(y, this) : x.Equals(y);
            }
            return y == null;
        }
开发者ID:bbenzikry,项目名称:impromptu-interface,代码行数:10,代码来源:Support.cs

示例15: TestEquals1

	public void TestEquals1() {
		{
			Object x = new Object();
			Object y = new Object();
			Assert("Object should equal itself",
			       x.Equals(x));
			Assert("object should not equal null",
			       !x.Equals(null));
			Assert("Different objects should not equal 1",
			       !x.Equals(y));
			Assert("Different objects should not equal 2",
			       !y.Equals(x));
		}
		{
			double x = Double.NaN;
			double y = Double.NaN;
			Assert("NaNs should always equal each other",
			       ((Object)x).Equals(y));
		}
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:20,代码来源:ObjectTest.cs


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