its*_*lur 9 c# linq string-concatenation
我正在使用C#和.Net 4.0.
我有List<string>一些值,比如x1,x2,x3.对于每个值List<string>,我需要连接一个常量值,比如"y"并返回List<string> x1y,x2y和x3y.
是否有Linq方法可以做到这一点?
Hab*_*bib 14
List<string> yourList = new List<string>() { "X1", "Y1", "X2", "Y2" };
yourList = yourList.Select(r => string.Concat(r, 'y')).ToList();
Run Code Online (Sandbox Code Playgroud)
另一种选择,使用ConvertAll:
List<string> l = new List<string>(new [] {"x1", "x2", "x3"} );
List<string> l2 = l.ConvertAll(x => x + "y");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8664 次 |
| 最近记录: |