.net List<T>
List的几个方法
List=>
List.Find()
List.FindAll()
List.Contains()
List.ForEach()
List.ConvertAll()
1. 先比较Find()跟FindAll()。 这个两个函数都是 遍历List的集合,只是 区别在于FindAll()返回的必须是一个List集合,而Find()可以返回字符串。
List<string> list = new List<string>();
list.Add("小三005");
list.Add("小四007");
list.Add("小五0105");
list.Add("小六007"); string names = list.Find(t => t.ToString().Substring(t.Length - , ) == "");
Console.WriteLine("names:{0}", names); List<string> sList = list.FindAll(t => t.ToString().Substring(t.Length - , ) == "");
foreach (string item in sList)
{
Console.WriteLine("sList:{0}", item);
}
Console.ReadLine();
2. List.Contains() 。Contains() 函数是查看List集合中是否存在某一值,返回的是 bool 值
List<string> list = new List<string>();
list.Add("小三005");
list.Add("小四007");
list.Add("小五0105");
list.Add("小六007");
if (list.Contains("小五0105"))
{
Console.WriteLine("list中存在=>小五0105");
}
else
{
Console.WriteLine("list中不存在=>小五0105");
}
3. List.ForEach() 。ForEach() 也是遍历List 集合,只是它没有返回值,可以跟普通语法的foreach() 一样。
List<string> list = new List<string>();
list.Add("小三005");
list.Add("小四007");
list.Add("小五0105");
list.Add("小六007");
list.ForEach(t => Console.WriteLine("list输出{0}", t.ToString()));
4.List.ConvertAll()。
List<string> list = new List<string>();
list.Add("小三005");
list.Add("小四007");
list.Add("小五0105");
list.Add("小六007");
List<string> cList = list.ConvertAll<string>( m=> m.ToString());
随机推荐
- switch控件的使用
java中: public class MainActivity extends Activity implements OnCheckedChangeListener{ private Switch ...
- 浅谈FPGA的选型
工欲善其事必先利其器,开发FPGA的第一步,当然是选择一片符合设计需求的芯片. 器件特色 选片第一个关注的应该是FPGA器件的专用资源. 例如是否需要高速接口,如果需要的话,需要多少个通道,各个通道需 ...
- ffmpeg摄像头采集h264编码RTP发送
一. 相关API说明 1. av_register_all 2. avformat_network_init 不管是流媒体发送还是流媒体接收, 需要先执行该函数. 3. avformat_alloc_ ...
- yii console
Here is a step by step to show how to run command in the server with yii framework. 1. Create the we ...
- 【转】使用Badboy录制脚本,作为JMeter测试的素材
接触Badboy,是因为JMeter要引用Badboy导出的脚本 Badboy的录制提供两个模式:Request(默认模式) 和navigation模式.点击下图N,切换模式:但是要导出到Jmeter ...
- java数组复制===clone()
总结:使用方法原理弄清楚 package com.a; public class gjsopb { public static void main(String[] args) { int a[] = ...
- iOS平台下闪退原因汇总(一):"Ran out of trampolines of type 0/1/2" 运行时间错误
"Ran out of trampolines of type 0/1/2" 运行时间错误通常出现在使用大量递归泛型时.要看到这个错误需要连接着设备直接将项目build到设备里运行 ...
- Ubantu下安装adobe flash player插件
用火狐看视频,要打开Adobe官网下载xxxx,太麻烦. 可以在Terminal下输入: apt-get install flashplugin-nonfree 好了.
- leetcode452
public class Solution { public int FindMinArrowShots(int[,] points) { // multidimensional array cann ...
- Hadoop Serialization -- hadoop序列化详解 (3)【ObjectWritable,集合Writable以及自定义的Writable】
前瞻:本文介绍ObjectWritable,集合Writable以及自定义的Writable TextPair 回顾: 前面了解到hadoop本身支持java的基本类型的序列化,并且提供相应的包装实现 ...