我是靠谱客的博主 靓丽月光,最近开发中收集的这篇文章主要介绍判断集合中的元素是否为某个类型或者存在某种类型,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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


namespace ConsoleApplication1
{
    partial class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            List<object> list = new List<object>();
            list.Add("ssssf");
            list.Add("ssssf");
            list.Add("ssssf");
            list.Add(1);
            //判断集合里的元素类型是否都是int类型,如果元素全部为int类型就会返回true
            bool b = list.All<object>(a);
            //判断集合里的元素类型是否包括int类型,只要有一个int类型元素就会返回true
            bool c = list.Any<object>(a);
            Console.Write(b);
            Console.Write(c);
            Console.ReadKey();
        }
        //此处是判断方法,通过委托传递给对应方法参数中
        static bool CheckElement(object a)
        {
            //判断的集合中的类型
            return a is int;
        }
        public static event Func<object, bool> a = CheckElement;
    }
}

最后

以上就是靓丽月光为你收集整理的判断集合中的元素是否为某个类型或者存在某种类型的全部内容,希望文章能够帮你解决判断集合中的元素是否为某个类型或者存在某种类型所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部