• .NET 4.0 数组比较


    代码
     1  /// <summary>
     2     /// New Feature in .NET 4.0
     3     /// Compare two array
     4     /// using IStructuralEquatable
     5     /// using EqualityComparer<T>
     6     /// using Comparer<T>
     7     /// </summary>
     8     class Program
     9     {
    10         static void Main(string[] args)
    11         {
    12             int[] arr1 = new int[]{
    13                 1,2,3,5
    14             };
    15             int[] arr2 = new int[]{
    16                 1,2,3,4
    17             };
    18 
    19             bool isEqual = (arr1 as IStructuralEquatable).Equals (
    20                 arr2, EqualityComparer <int>.Default );
    21 
    22             int bigger = (arr1 as IStructuralComparable).CompareTo(
    23                 arr2, Comparer<int>.Default);
    24 
    25             Console.WriteLine(String.Format ("arr1==arr2 :{0}",isEqual));
    26             Console.WriteLine(String.Format("arr1-arr3: {0}",bigger));
    27 
    28             Console.WriteLine("");
    29 
    30             string[] str1 = new string[]{
    31                 "a","cb"
    32             };
    33             string[] str2 = new string[]{
    34                 "a","c"
    35             };
    36 
    37             // if str1=str2 then sbigger=0 ; if str1>str2 then sbigger=1; if str1<str2 then sbigger=-1
    38             int sbigger = (str1 as IStructuralComparable).CompareTo(
    39                 str2, Comparer<string>.Default);
    40             Console.WriteLine(String.Format ("str1-str2:{0}",sbigger));            
    41         }
    42     }
    Output:
     
     
  • 相关阅读:
    hdu 1260 Tickets
    hdu 4738 Caocao's Bridges(桥的最小权值+去重)
    找规律
    C语言快速排序
    数组的初始化方法
    C语言选择排序
    副本机制
    安装完Kali的后续操作
    Bool盲注
    Python中的列表
  • 原文地址:https://www.cnblogs.com/qixue/p/1639110.html
Copyright © 2020-2023  润新知