• .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:
     
     
  • 相关阅读:
    flask 数据迁移
    docker daemon 配置代理
    dbcm with kubenetes
    curl 访问 k8s
    kubernetes 集群安全配置
    k8s dashboard
    k8s v1.5.8 单节点搭建
    etcd raft library
    split files test
    ubuntu两个python版本共存并切换默认版本
  • 原文地址:https://www.cnblogs.com/qixue/p/1639110.html
Copyright © 2020-2023  润新知