概述
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;
}
}
最后
以上就是靓丽月光为你收集整理的判断集合中的元素是否为某个类型或者存在某种类型的全部内容,希望文章能够帮你解决判断集合中的元素是否为某个类型或者存在某种类型所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复