Cast List< int>到List< string>在.NET 2.0 [英] Cast List<int> to List<string> in .NET 2.0
本文介绍了Cast List< int>到List< string>在.NET 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以将列表< int>
转换为列表< string>
吗?
我知道我可以循环遍历和.ToString()的东西,但一个演员会是真棒。
I know I could loop through and .ToString() the thing, but a cast would be awesome.
2.0(因此没有 LINQ )。
I'm in C# 2.0 (so no LINQ).
推荐答案
.NET 2.0有 ConvertAll
方法,您可以在其中传递转换函数:
.NET 2.0 has the ConvertAll
method where you can pass in a converter function:
List<int> l1 = new List<int>(new int[] { 1,2,3 } );
List<string> l2 = l1.ConvertAll<string>(delegate(int i) { return i.ToString(); });
这篇关于Cast List< int>到List< string>在.NET 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文