比如有一个如下IEnumerable类型名为post的对象
IEnumerable<string> post = new List{
"hello",
"world"
};将IEnumerable类型转换为ICollection类型有如下方法
方法1:强制转换
ICollection<string> c = (ICollection<string>)post;方法2:使用List类型进行转换
ICollection<string> c = post.ToList();
本文介绍了一种常见的类型转换场景:如何将IEnumerable<string>类型的对象转换为ICollection<string>类型,并提供了两种实用的方法。
比如有一个如下IEnumerable类型名为post的对象
IEnumerable<string> post = new List{
"hello",
"world"
};将IEnumerable类型转换为ICollection类型有如下方法
方法1:强制转换
ICollection<string> c = (ICollection<string>)post;方法2:使用List类型进行转换
ICollection<string> c = post.ToList();
211

被折叠的 条评论
为什么被折叠?
