演员表&LT;&诠释GT;列出&LT;串GT;在.NET 2.0 [英] Cast List<int> to List<string> in .NET 2.0
本文介绍了演员表&LT;&诠释GT;列出&LT;串GT;在.NET 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以施放一个列表&LT; INT&GT;
到列表&LT;串&GT;
不知何故
Can you cast a List<int>
to List<string>
somehow?
我知道我可以遍历和的ToString()的东西,但投将是真棒。
I know I could loop through and .ToString() the thing, but a cast would be awesome.
我在C#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(); });
这篇关于演员表&LT;&诠释GT;列出&LT;串GT;在.NET 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文