Пример #1
0
        /// <inheritdoc />
        /// <example>
        /// <code source="..\..\Source\Examples\ExampleLibraryCSharp\DataStructures\General\BagExamples.cs" region="Equals" lang="cs" title="The following example shows how to use the Equals method."/>
        /// <code source="..\..\Source\Examples\ExampleLibraryVB\DataStructures\General\BagExamples.vb" region="Equals" lang="vbnet" title="The following example shows how to use the Equals method."/>
        /// </example>
        public bool Equals(Bag <T> other)
        {
            #region Validation

            if (other == null)
            {
                return(false);
            }

            #endregion


            if (Count != other.Count)
            {
                return(false);
            }

            foreach (var item in data)
            {
                if (!other.Contains(item.Key))
                {
                    return(false);
                }

                if (other[item.Key] != item.Value)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        /// <inheritdoc />
        /// <example>
        /// <code source="..\..\NGenerics.Examples\DataStructures\General\BagExamples.cs" region="Equals" lang="cs" title="The following example shows how to use the Equals method."/>
        /// </example>
        public bool Equals(Bag <T> other)
        {
            if (Count != other?.Count)
            {
                return(false);
            }

            foreach (var item in _data)
            {
                if (!other.Contains(item.Key))
                {
                    return(false);
                }

                if (other[item.Key] != item.Value)
                {
                    return(false);
                }
            }

            return(true);
        }