• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# IComparable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IComparable的典型用法代码示例。如果您正苦于以下问题:C# IComparable类的具体用法?C# IComparable怎么用?C# IComparable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IComparable类属于命名空间,在下文中一共展示了IComparable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Field

        public Field(XmlElement elField)
        {
            String typeName = elField.GetAttribute("type");
            string lbStr = elField.GetAttribute("lower-bound");
            string ubStr = elField.GetAttribute("upper-bound");
            string fieldTypeStr = elField.GetAttribute("fieldtype");
            string valueStr = elField.InnerText;

            type = ClassTypes.GetType(typeName);
            fieldType = ParseTypeString(fieldTypeStr);

            if (!Formal)
            {
                value = ParseFieldValue(type, valueStr);
            }
            else
            {
                if (lbStr != null)
                {
                    lowerBound = (IComparable) ParseFieldValue(type, lbStr);
                }
                if (ubStr != null)
                {
                    upperBound = (IComparable) ParseFieldValue(type, ubStr);
                }
            }
        }
开发者ID:pepipe,项目名称:ISEL,代码行数:27,代码来源:Field.cs


示例2: Sort

        public override void Sort(IComparable[] a)
        {
            int n = a.Length;
            int h = 1;
            int arrayLength = 1;

            while (h < n / 3)
            {
                h = h * 3 + 1;
                arrayLength++;
            }

            int[] hmas = new int[arrayLength--];
            hmas[arrayLength--] = h;
            h = h / 3;
            while (h >= 1)
            {
                hmas[arrayLength--] = h;
                h = h / 3;
            }

            for (int k = hmas.Length - 1; k >= 0; k--)
            {
                for (int i = hmas[k]; i < n; i++)
                {
                    for (int j = i; j > 0 && less(a[j], a[j - 1]); j -= h)
                    {
                        exch(a, j, j - 1);
                    }
                }
            }
        }
开发者ID:elcrespito,项目名称:ClassicAlgorightms,代码行数:32,代码来源:ShellInArray.cs


示例3: DevideCommand_Test

        public void DevideCommand_Test()
        {
            var inputStringCommand = new[]
            {
                "5 5\r\n1 2 N\r\nLMLMLMLMM\r\n",
                "5 5\r\n1 2 N\r\nLMLMLMLMM\r\n1 2 N"
            };

            var outputValues = new IComparable[]
            {
                3,
                "ERROR"
            };

            for (int i = 0; i < inputStringCommand.Length; i++)
            {
                try
                {
                    DevideCommand devideCommand = new DevideCommand(inputStringCommand[i]);

                    Assert.AreEqual(devideCommand.GetArrayListCommand.Length, outputValues[i]);
                }
                catch (DevideCommandException exceptionDevideCommand)
                {
                    Assert.AreEqual(exceptionDevideCommand.Message, "Не достаточно данных для отправки");
                }
            }
        }
开发者ID:aSosunoff,项目名称:Robot_D,代码行数:28,代码来源:DevideCommandTest.cs


示例4: XIntervalSeries

 public XIntervalSeries(IComparable key, bool autoSort, bool allowDuplicateXValues)
 {
   int num1 = autoSort ? 1 : 0;
   int num2 = allowDuplicateXValues ? 1 : 0;
   // ISSUE: explicit constructor call
   base.\u002Ector(key, num1 != 0, num2 != 0);
 }
开发者ID:NALSS,项目名称:SmartDashboard.NET,代码行数:7,代码来源:XIntervalSeries.cs


示例5: Insert

		/// <summary> Insert into the tree. Does nothing if item already present.
		/// </summary>
		/// <param name="item">the item to insert.
		/// </param>
		public virtual void  Insert(IComparable item)
		{
			current = parent = grand = header;
			nullNode.element = item;

			while (current.element.CompareTo(item) != 0)
			{
				great = grand; grand = parent; parent = current;
				current = item.CompareTo(current.element) < 0?current.left:current.right;

				// Check if two red children; fix if so
				if (current.left.color == RED && current.right.color == RED)
					handleReorient(item);
			}

			// Insertion fails if already present
			if (current != nullNode)
				return ;
			current = new RedBlackNode(item, nullNode, nullNode);

			// Attach to parent
			if (item.CompareTo(parent.element) < 0)
				parent.left = current;
			else
				parent.right = current;
			handleReorient(item);
		}
开发者ID:sillsdev,项目名称:WorldPad,代码行数:31,代码来源:RedBlackTree.cs


示例6: Search

        public virtual IList Search(IComparable key)
        {
            var positionOfKey = GetPositionOfKey(key);
            var keyIsHere = positionOfKey > 0;
            int realPosition;
            
            if (keyIsHere)
            {
                realPosition = positionOfKey - 1;
                var valueAsList = GetValueAt(realPosition);

                return valueAsList;
            }
            
            if (IsLeaf())
            {
                // key is not here and node is leaf
                return null;
            }

            realPosition = -positionOfKey - 1;
            
            var node = (IBTreeNodeMultipleValuesPerKey) GetChildAt(realPosition, true);
            return node.Search(key);
        }
开发者ID:SchwarzerLoewe,项目名称:Paint,代码行数:25,代码来源:BTreeNodeMultipleValuesPerKey.cs


示例7: DoMerge

        public void DoMerge(IComparable[] numbers, int left, int mid, int right)
        {
            IComparable[] temp = new IComparable[arraySize];
            int i, left_end, num_elements, tmp_pos;

            left_end = (mid - 1);
            tmp_pos = left;
            num_elements = (right - left + 1);

            while ((left <= left_end) && (mid <= right))
            {
                if (numbers[left].CompareTo(numbers[mid]) <= 0)
                    temp[tmp_pos++] = numbers[left++];
                else
                    temp[tmp_pos++] = numbers[mid++];
            }

            while (left <= left_end)
                temp[tmp_pos++] = numbers[left++];

            while (mid <= right)
                temp[tmp_pos++] = numbers[mid++];

            for (i = 0; i < num_elements; i++)
            {
                numbers[right] = temp[right];
                right--;
            }
        }
开发者ID:andrejs201,项目名称:cis237assignment4,代码行数:29,代码来源:MergeSort.cs


示例8: IsGreaterOrEqual

        /// <summary>
        /// Indicates whether the instance is greater or equal to the reference value.
        /// </summary>
        /// <param name="value">The instance to test.</param>
        /// <param name="referenceValue">The reference value to test.</param>
        /// <returns><strong>true</strong> if the instance is greater or equal to the reference
        /// value; otherwise, <strong>false</strong>.</returns>
        /// <exception cref="ArgumentNullException"><em>value</em> or <em>referenceValue</em> is
        /// <strong>null</strong>.</exception>
        public static bool IsGreaterOrEqual(this IComparable value, IComparable referenceValue)
        {
            Precondition.IsNotNull(value, nameof(value));
            Precondition.IsNotNull(referenceValue, nameof(referenceValue));

            return value.IsGreater(referenceValue) || value.IsEqual(referenceValue);
        }
开发者ID:akordowski,项目名称:NToolbox,代码行数:16,代码来源:ComparableExtension.cs


示例9: enqueue

 public void enqueue(IComparable item)
 {
     if (lastIndex == maxIndex)
         throw new Exception("Priority queue is full");
     lastIndex = lastIndex + 1;
     reheapUp(item);
 }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:7,代码来源:Heap.cs


示例10: GetValues

        protected override IEnumerable<long> GetValues(ISonesIndex myIndex, IComparable myIComparable)
        {
            if (myIndex is ISonesRangeIndex)
            {
                //use the range funtionality
                foreach (var aVertexID in ((ISonesRangeIndex)myIndex).LowerThan(myIComparable, true))
                {
                    yield return aVertexID;
                }
            }
            else
            {
                //stupid, but works

                foreach (var aVertexIDSet in myIndex.Keys().Where(key => key.CompareTo(myIComparable) <= 0).Select(key => myIndex[key]))
                {
                    foreach (var aVertexID in aVertexIDSet)
                    {
                        yield return aVertexID;
                    }
                }
            }

            yield break;
        }
开发者ID:ramz,项目名称:sones,代码行数:25,代码来源:QueryPlanLessOrEqualsThanWithIndex.cs


示例11: IsGreater

        /// <summary>
        /// Indicates whether the instance is greater as the reference value.
        /// </summary>
        /// <param name="value">The instance to test.</param>
        /// <param name="referenceValue">The reference value to test.</param>
        /// <returns><strong>true</strong> if the instance is greater as the reference value;
        /// otherwise, <strong>false</strong>.</returns>
        /// <exception cref="ArgumentNullException"><em>value</em> or <em>referenceValue</em> is
        /// <strong>null</strong>.</exception>
        public static bool IsGreater(this IComparable value, IComparable referenceValue)
        {
            Precondition.IsNotNull(value, nameof(value));
            Precondition.IsNotNull(referenceValue, nameof(referenceValue));

            return value.CompareTo(referenceValue) == 1;
        }
开发者ID:akordowski,项目名称:NToolbox,代码行数:16,代码来源:ComparableExtension.cs


示例12: Quicksort

    public static void Quicksort(IComparable[] elements, int left, int right)
    {
        int leftIndex = left, rightIndex = right;
        IComparable pivot = elements[(left + right) / 2];

        while (leftIndex <= rightIndex)
        {
            while (elements[leftIndex].CompareTo(pivot) < 0)
            {
                leftIndex++;
            }
            while (elements[rightIndex].CompareTo(pivot) > 0)
            {
                rightIndex--;
            }
            if (leftIndex <= rightIndex)
            {
                IComparable temp = elements[leftIndex];
                elements[leftIndex] = elements[rightIndex];
                elements[rightIndex] = temp;
                leftIndex++;
                rightIndex--;
            }
        }
        if (left < rightIndex)
        {
            Quicksort(elements, left, rightIndex);
        }

        if (leftIndex < right)
        {
            Quicksort(elements, leftIndex, right);
        }
    }
开发者ID:RamiAmaire,项目名称:TelerikAcademy,代码行数:34,代码来源:QuickSort.cs


示例13: ArgumentInRange

 public static void ArgumentInRange(IComparable argument, IComparable minimum, IComparable maximum, string paramName = DefaultParamName)
 {
     if (argument.CompareTo(minimum) < 0 || argument.CompareTo(maximum) > 0)
     {
         throw new ArgumentException(string.Format("{0} must be between {1} and {2}.", paramName, minimum, maximum), paramName);
     }
 }
开发者ID:shanet,项目名称:Asimov,代码行数:7,代码来源:Verify.cs


示例14: ArgumentAtMost

 public static void ArgumentAtMost(IComparable argument, IComparable maximum, string paramName = DefaultParamName)
 {
     if (argument.CompareTo(maximum) > 0)
     {
         throw new ArgumentException(string.Format("{0} must be at most {1}.", paramName, maximum), paramName);
     }
 }
开发者ID:shanet,项目名称:Asimov,代码行数:7,代码来源:Verify.cs


示例15: Partition_Version_One

        private int Partition_Version_One(IComparable[] a, int lo, int hi)
        {
            int i = lo;
            int j = hi + 1;
            IComparable value = a[lo];

            while (true)
            {
                while (Less(a[++i], value))
                {
                    if (i == hi) break;
                }

                while (Less(value, a[--j]))
                {
                    if (j == lo) break;
                }

                if (i >= j)
                {
                    break;
                }

                Exchange(a, i, j);
            }

            Exchange(a, lo, j);

            return j;
        }
开发者ID:hong-rong,项目名称:MyRepository,代码行数:30,代码来源:QuickSort.cs


示例16: sort

 private static void sort(IComparable[] a, int lo, int hi)
 {
     if (hi <= lo) return;
     int j = partition(a, lo, hi);
     sort(a, lo, j - 1); // Sort left part a[lo .. j-1].
     sort(a, j + 1, hi); // Sort right part a[j+1 .. hi].
 }
开发者ID:kaplunov93,项目名称:Algorithms,代码行数:7,代码来源:Quick.cs


示例17: InsertKeyAndValue

        public override void InsertKeyAndValue(IComparable key, object value)
        {
            var position = GetPositionOfKey(key);
            var addToExistingCollection = false;
            int realPosition;

            if (position >= 0)
            {
                addToExistingCollection = true;
                realPosition = position - 1;
            }
            else
            {
                realPosition = -position - 1;
            }

            // If there is an element at this position and the key is different,
            // then right shift, size
            // safety is guaranteed by the rightShiftFrom method
            if (realPosition < NbKeys && key.CompareTo(Keys[realPosition]) != 0)
                RightShiftFrom(realPosition, true);

            Keys[realPosition] = key;
            
            // This is a non unique btree node, manage collection
            ManageCollectionValue(realPosition, value);
            
            if (!addToExistingCollection)
                NbKeys++;
        }
开发者ID:SchwarzerLoewe,项目名称:Paint,代码行数:30,代码来源:BTreeNodeMultipleValuesPerKey.cs


示例18: GetMultipleIndexValues

        public override IEnumerable<long> GetMultipleIndexValues(IMultipleValueIndex<IComparable, long> myMultipleValueIndex, IComparable myIComparable)
        {
            if (myMultipleValueIndex is IRangeIndex<IComparable, long>)
            {
                //use the range funtionality

                foreach (var aVertexIDSet in ((IMultipleValueRangeIndex<IComparable, long>)myMultipleValueIndex).LowerThan(myIComparable, false))
                {
                    foreach (var aVertexID in aVertexIDSet)
                    {
                        yield return aVertexID;
                    }
                }
            }
            else
            {
                //stupid, but works

                foreach (var aVertexIDSet in myMultipleValueIndex.Where(kv => kv.Key.CompareTo(myIComparable) < 0).Select(kv => kv.Value))
                {
                    foreach (var aVertexID in aVertexIDSet)
                    {
                        yield return aVertexID;
                    }
                }
            }

            yield break;
        }
开发者ID:loubo,项目名称:sones,代码行数:29,代码来源:QueryPlanLessThanWithIndex.cs


示例19: MergeSort

 //takes in array and area of the array that is populated
 public MergeSort(IComparable[] array, int length)
 {
     this.arraySize = length;
     this.array = array;
     //mergesort is called from the constructor
     MergeSort_Recursive(this.array, 0, arraySize - 1);
 }
开发者ID:andrejs201,项目名称:cis237assignment4,代码行数:8,代码来源:MergeSort.cs


示例20: ArithmeticCriteria

        /// <summary>
        /// Initializes a new instance of the <see cref="ArithmeticCriteria"/> class.
        /// </summary>
        /// <param name="fieldName">Name of the field.</param>
        /// <param name="value">The value.</param>
        /// <param name="operand">The operand.</param>
        public ArithmeticCriteria(string fieldName, IComparable value, ArithmeticOperandEnum operand)
            : base(fieldName)
        {
            if (value == null)
            {
                ThrowHelper.ThrowArgumentNullException("value");
            }

            Type valueType = value.GetType();
            if (valueType.IsGenericType && valueType.GetGenericTypeDefinition().Equals(typeof(EntityBaseGenericId<>)))
            {
                dynamic dynValue = value;
                if (dynValue.Id == null)
                {
                    ThrowHelper.ThrowArgumentException(String.Format("Provided entity has not got identifier. Entity type: '{0}'.", valueType.FullName), "value");
                }
                if (fieldName.ToLower().Equals("id"))
                {
                    this.FieldName = fieldName;
                }
                else
                {
                    this.FieldName = fieldName.ToLower().EndsWith(".id") ? fieldName : String.Format("{0}.id", fieldName);
                }
                this.mValue = dynValue.Id;
            }
            else
            {
                this.mValue = value;
            }
            this.mOperand = operand;
        }
开发者ID:JZO001,项目名称:Forge,代码行数:38,代码来源:ArithmeticCriteria.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IComparer类代码示例发布时间:2022-05-24
下一篇:
C# ICommunity类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap