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


C# Object.Equals方法代码示例

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


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

示例1: PosTest1

    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Compare two empty object instances");

        try
        {
            Object obj1 = new Object();
            Object obj2 = new Object();

            if (obj1.Equals(obj2))
            {
                TestLibrary.TestFramework.LogError("001", "Two empty object instances are equal");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:26,代码来源:objectequals1.cs

示例2: Check

 static public void Check(TypedReference r, Object v) {
     if (!v.Equals(TypedReference.ToObject(r))) {
         Console.WriteLine("Expected: " + v);
         Console.WriteLine("Actual: " + TypedReference.ToObject(r));
         Environment.Exit(1);
     }
  }
开发者ID:ArildF,项目名称:masters,代码行数:7,代码来源:multidimmarray.cs

示例3: Equals

		public override bool Equals (Object obj)
		{
			if (!(obj is LockCookie)) {
				return(false);
			}
			
			return(obj.Equals (this));
		}
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:8,代码来源:LockCookie.cs

示例4: IIF

    public static System.Object IIF(Object Arg1, Object Arg2, String ACondition, Object ATrueValue, Object AFalseValue)
    {
        if (Arg1.Equals(DBNull.Value) || Arg2.Equals(DBNull.Value)) { return DBNull.Value; };
        if (Arg1.GetType() != Arg2.GetType()) { return DBNull.Value; };
        int Compare = ((IComparable)Arg1).CompareTo(Arg2);

        switch (ACondition)
        {
            case "=" : if (Compare == 0) { return ATrueValue; } else { return AFalseValue; };
            case "<>": if (Compare != 0) { return ATrueValue; } else { return AFalseValue; };
            case "!=": if (Compare != 0) { return ATrueValue; } else { return AFalseValue; };
            case ">" : if (Compare > 0)  { return ATrueValue; } else { return AFalseValue; };
            case "<" : if (Compare < 0)  { return ATrueValue; } else { return AFalseValue; };
            case ">=": if (Compare >= 0) { return ATrueValue; } else { return AFalseValue; };
            case "<=": if (Compare <= 0) { return ATrueValue; } else { return AFalseValue; };
        }
        return DBNull.Value;
    }
开发者ID:APouchkov,项目名称:ExtendedStoredProcedures,代码行数:18,代码来源:IIF+-+копия.cs

示例5: Contains

	public virtual bool Contains(Object key)
			{
				ICollection keys = Keys;
				if(keys != null && key != null)
				{
					foreach(Object value in keys)
					{
						if(key.Equals(value))
						{
							return true;
						}
					}
					return false;
				}
				else
				{
					return false;
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:19,代码来源:BaseChannelObjectWithProperties.cs

示例6: Equals

#pragma warning restore 618

        public new bool Equals(Object a, Object b) {
            if (a == b) return true;
            if (a == null || b == null) return false;
            
            // We must call Compare or CompareTo method
            // to make sure everything is fine, but the 
            // guideline is that Equals should never throw.
            // So we need to swallow ArgumentException (note this
            // is the exception we should get if two objects are not
            // comparable.)

            try {
                if (_comparer != null)
                    return (_comparer.Compare(a,b) == 0);

                IComparable ia = a as IComparable;
                if (ia != null)
                    return (ia.CompareTo(b) ==0);
            }
            catch(ArgumentException) {
                return false;
            }

            return a.Equals(b);
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:27,代码来源:nameobjectcollectionbase.cs

示例7: KeyEquals

        // Internal method to compare two keys.  If you have provided an IComparer
        // instance in the constructor, this method will call comparer.Compare(item, key).
        // Otherwise, it will call item.Equals(key).
        // 
        protected virtual bool KeyEquals(Object item, Object key)
        {
            Debug.Assert(key != null, "key can't be null here!");
            if (Object.ReferenceEquals(_buckets, item))
            {
                return false;
            }

            if (Object.ReferenceEquals(item, key))
                return true;

            if (_keycomparer != null)
                return _keycomparer.Equals(item, key);
            return item == null ? false : item.Equals(key);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:19,代码来源:Hashtable.cs

示例8: SubMap

        /// <summary>
        /// Returns a portion of the list whose keys are greater that the lowerLimit parameter less than the upperLimit parameter.
        /// </summary>
        /// <param name="list">The list where the portion will be extracted.</param>
        /// <param name="lowerLimit">The start element of the portion to extract.</param>
        /// <param name="upperLimit">The end element of the portion to extract.</param>
        /// <returns>The portion of the collection.</returns>
        public static System.Collections.SortedList SubMap(System.Collections.SortedList list, Object lowerLimit, Object upperLimit)
        {
            System.Collections.Comparer comparer = System.Collections.Comparer.Default;
            System.Collections.SortedList newList = new System.Collections.SortedList();

            if (list != null)
            {
                if ((list.Count > 0) && (!(lowerLimit.Equals(upperLimit))))
                {
                    int index = 0;
                    while (comparer.Compare(list.GetKey(index), lowerLimit) < 0)
                        index++;

                    for (; index < list.Count; index++)
                    {
                        if (comparer.Compare(list.GetKey(index), upperLimit) >= 0)
                            break;

                        newList.Add(list.GetKey(index), list[list.GetKey(index)]);
                    }
                }
            }

            return newList;
        }
开发者ID:heon21st,项目名称:flashdevelop,代码行数:32,代码来源:SupportClass.cs

示例9: KeyEquals

 protected virtual bool KeyEquals(Object item, Object key)
 {
     //用于判断两key是否相等
     return item == null ? false : item.Equals(key);
 }
开发者ID:yfann,项目名称:CSharp_Algorithm,代码行数:5,代码来源:MyHashTable.cs

示例10: testS1


//.........这里部分代码省略.........
            S1.create2(new Context(Context.test_kind.NO_FACTORY));
        } catch (ucss.uno.DeploymentException e) {
            l.assure(e.Message.Length > 0);
        } catch (System.Exception) {
            l.assure(false);
        }

        /* When the service manager returns a null pointer then a DeploymentException
         * is to be thrown.
         */
        try {
            S1.create2(new Context(Context.test_kind.CREATION_FAILED));
        } catch (ucss.uno.DeploymentException e) {
            l.assure(e.Message.Length > 0);
        } catch (System.Exception) {
            l.assure(false);
        }


        /** Test creation of components and if the passing of parameters works.
         */
        c = new Context(Context.test_kind.NORMAL);
        try {
            XTest xTest = S1.create1(c);
            Component cobj = (Component) xTest;
            l.assure(cobj.Args[0].Value == c);

            Any a1 = new Any("bla");
            Any a2 = new Any(3.14f);
            Any a3 = new Any(3.145d);
            xTest = S1.create2(c, a1, a2, a3);
            cobj = (Component) xTest;
            l.assure(cobj.Args[0].Value == c
                     && a1.Equals(cobj.Args[1])
                     && a2.Equals(cobj.Args[2])
                     && a3.Equals(cobj.Args[3]));

            bool b1 = true;
            byte b2 = 1;
            short b3 = 2;
            ushort b4 = 3;
            int b5 = 4;
            uint b6 = 5;
            long b7 = 6;
            ulong b8 = 7;
            float b9 = 0.8f;
            double b10 = 0.9;
            char b11 = 'A';
            string b12 = "BCD";
            Type b13 = typeof(ulong);
            Any b14 = new Any(22);
            Enum2 b15 = Enum2.VALUE4;
            Struct1 b16 = new Struct1(1);
            PolyStruct b17 = new PolyStruct('A', 1);
            PolyStruct b18 = new PolyStruct(new Any(true), 1);
            object b19 = new uno.util.WeakComponentBase();
            ucss.lang.XComponent b20 = (ucss.lang.XComponent) b19;
            bool b21 = b1;
            byte b22 = b2;
            short b23 = b3;
            ushort b24 = b4;
            int b25 = b5;
            uint b26 = b6;
            long b27 = b7;
            ulong b28 = b8;
            float b29 = b9;
开发者ID:sdmckenzie,项目名称:core,代码行数:67,代码来源:climaker.cs

示例11: Equals

	// Determine if two instances of this class are equal.
	public override bool Equals(Object obj)
			{
				DefaultValueAttribute other = (obj as DefaultValueAttribute);
				if(other != null)
				{
					return obj.Equals(other.obj);
				}
				else
				{
					return false;
				}
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:13,代码来源:DefaultValueAttribute.cs

示例12: GetMessageValue

        public virtual Object this[Object key]
        {
            get
            { 
                System.String skey = key as System.String;
                if (null != skey) 
                { 
                    for (int i=0; i<_keys.Length; i++)
                    { 
                        if (skey.Equals(_keys[i]))
                        {
                            return GetMessageValue(i);
                        } 
                    }
                    if (_dict != null) 
                    { 
                        return _dict[key];
                    } 
                }
                return null;
            }
            [System.Security.SecuritySafeCritical] // 
            set
            { 
                if (ContainsSpecialKey(key)) 
                {
                    if (key.Equals(Message.UriKey)) 
                    {
                        SetSpecialKey(0,value);
                    }
                    else if (key.Equals(Message.CallContextKey)) 
                    {
                        SetSpecialKey(1,value); 
                    } 
                    else
                    { 
                        throw new ArgumentException(
                            Environment.GetResourceString(
                                "Argument_InvalidKey"));
                    } 
                }
                else 
                { 
                    if (_dict == null)
                    { 
                        _dict = new Hashtable();
                    }
                    _dict[key] = value;
                } 

            } 
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:52,代码来源:Message.cs

示例13: compareData

        static bool compareData(Object val1, Object val2)
        {
            if (val1 == null && val2 == null || val1 == val2)
            return true;
            if ((val1 == null && val2 != null) ||
            (val1 != null && val2 == null) || val1.GetType() != val2.GetType())
            return false;

            bool ret = false;
            Type t1  = val1.GetType();
            //Sequence
            if (t1.IsArray)
            {
            ret = compareSequence((Array) val1, (Array) val2);
            }
            //String
            else if (t1 == typeof(string))
            {
            ret = (string) val1 == (string) val2;
            }
            // Interface implementation
            else if (t1.GetInterfaces().Length > 0 && ! t1.IsValueType)
            {
            ret = val1 == val2;
            }
            // Struct
            else if ( ! t1.IsValueType)
            {
            ret = compareStruct(val1, val2);
            }
            else if (t1 == typeof(Any))
            {
            Any a1 = (Any) val1;
            Any a2 = (Any) val2;
            ret = a1.Type == a2.Type && compareData(a1.Value, a2.Value);
            }
            else if (t1.IsValueType)
            {
            //Any, enum, int, bool char, float, double etc.
            ret = val1.Equals(val2);
            }
            else
            {
            Debug.Assert(false);
            }
            return ret;
        }
开发者ID:Echo360,项目名称:LibreOffice-core,代码行数:47,代码来源:cli_cs_bridgetest.cs

示例14: IdentityHashtable

		public IdentityHashtable() : base(128) {} // avoid expansation of hashtable

		// Determine if an item is equal to a key value.
		protected override bool KeyEquals(Object item, Object key)
				{
					if(item is String)
					{
						// Strings with the same value compare as equal.
						return item.Equals(key);
					}
					else
					{
						// Everything else needs object identity.
						return (item == key);
					}
				}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:16,代码来源:ObjectIDGenerator.cs

示例15: PosTest4

    public bool PosTest4()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest4: Compare an object with itself");

        try
        {
            Object obj = new Object();

            if (!obj.Equals(obj))
            {
                TestLibrary.TestFramework.LogError("008", "An object does not equal with itself");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("009", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:25,代码来源:objectequals1.cs


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