C#通用列表TrueForAll方法 [英] C# Generic List TrueForAll Method

查看:860
本文介绍了C#通用列表TrueForAll方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了记录我已经在谷歌上花了好几个小时试图获得更多关于这种方法的例子,(这些页面比一个人的衣橱更加紫色,而这个人的衣服是这种颜色的狂热者。)所以我要去海峡。题。您能给我一些在通用列表中使用TrueForAll方法的示例,特别是检查List的所有对象是否为空以及List是否为空。请保持答案简单,但不要太简单,它不会给我任何有用的信息。非常感谢你提前。我很感激每一个答案。祝你有美好的一天。 :)

For the record I have been on Google for hours trying to get more examples of this method, (The pages are more purple than a person's wardrobe who is a fanatic for the color.) so I am going to go strait to the question. Would you give me examples of use of the TrueForAll Method in the Generic List, specifically to check if all the List's objects are null and if the List is empty. Please keep the answers simple but not too simple that it gives me no usable information. Thank you very much in advance. I appreciate every answer. Have a good day. :)

推荐答案

List<object> items = new List(); 

//Add items, etc...

if (items.TrueForAll(item => item == null))
  //Everything is null





对于空的,只需这样做:





For the empty, just do:

if (items.Count == 0)


这篇关于C#通用列表TrueForAll方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆