工作总结 string数组 排序 string数组 比较

 

用到   工具类 Array 创建、处理、搜索数组并对数组进行排序

                      Enumerable  提供一组用于查询实现 System.Collections.Generic.IEnumerable<T> 的对象的 static(在 Visual

// Basic 中为 Shared)方法。      实现了 IEnumerable<T>类 的 

 

 

 

 

 

c# 比较两个数组每一个值是否相等

 

 int[] a = new int[] { 1, 2, 4, 5 };
int[] b = new int[] { 1, 3, 4, 5 };
            if (Enumerable.SequenceEqual(a,b))
            {
                label1.Text = "一样";
            }

Enumerable.SequenceEqual(strs1, strs2)

通过使用相同类型的默认相等比较器对序列元素进行比较,以确定两个序列是否相等。

 

 

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace demo1
{
    static class Help
    {
        public static Guid TogGuid(this object value)
        {
            try
            {
                if (value == null) return Guid.Empty;
                else
                {
                    if (value == "") return Guid.Empty;
                    else return new Guid(value.ToString());
                }
            }
            catch { return Guid.Empty; }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int s = 5;
            decimal s2 = (decimal)0.2577;
            decimal s3 = s / s2;
            Console.WriteLine(s3);
            //string s = "";
            //string m = null;
            //var ssd = s.TogGuid();
            //var ssdss = m.TogGuid();
            //Console.WriteLine(s.TogGuid());
            //Console.WriteLine(m.TogGuid());
            //object s =null;
            //default(T);
            Console.WriteLine(default(Guid));
            Console.WriteLine(default(int));
            Console.WriteLine(default(Nullable<int>));
            Console.WriteLine(default(string));
            Console.WriteLine(default(object));


            string a = "01,02,05,03,00";
            string b = "01,02,05,00";

            string[] aa = a.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            string[] bb = b.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            //aa = b.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            Array.Sort(aa);
            Array.Sort(bb);
            Console.WriteLine(Enumerable.SequenceEqual(aa, bb));
            //IEnumerable

            int[] asdasp = { 1, 2, 3 };
            //asdasp.Contains()                 IEnumerable<TSource>       支持的
            Console.WriteLine(asdasp.Sum());       //  每个数组都实现了IEnumerable<T>    所以可以使用 IEnumerable<T> 的扩展方法 (static class Enumerable 中)
            //  Enumerable   static class    IEnumerable<T> 工具类
            //所以 Enumerable.SequenceEqual 支持 int 的数组

            //Enumerable类  工具类      提供一组用于查询实现 System.Collections.Generic.IEnumerable<T> 的对象的 static(在 Visual
            //     Basic 中为 Shared)方法。
            //asdasp.SequenceEqual()      这样也支持的
            //扩展方法的另一种写法
            int[] asdasp2 = { 1, 2, 3 };
            asdasp.SequenceEqual(asdasp2);
            Enumerable.SequenceEqual(asdasp, asdasp2);

            //string[] b = { "", "", "", "", "", "" };

            //其他的也一样  通过使用默认的相等比较器确定序列是否包含指定的元素。
            //  public static bool Contains<TSource>(this IEnumerable<TSource> source, TSource value);
            //1
            asdasp2.Contains(5);     // 对象点 的方式 就需要写一个参数
            //2
            Enumerable.Contains(asdasp2, 5);   // 静态类点 的方式 就需要写两个参数


        }

    }
}

 

 

 

 效果一样

 

 

 

 

// 其实每个集合都实现了 IEnumerable<T> 集合 数组 都实现 IEnumerable<T> 所以可以使用 IEnumerable<T> 的扩展方法 (static class Enumerable 中)
// Enumerable static class IEnumerable<T> 工具类

转载于:https://www.cnblogs.com/cjm123/p/8989134.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值