【发布时间】:2013-03-23 10:55:20
【问题描述】:
我在下面的采访中遇到过这个问题?
让我们考虑名为的字符串
string gowtham="test1,test2,test3" ;
我需要转换成 IEnumerable 字符串函数
我需要一个输出作为
new[] {"test1", "test2","test3" }
我所做的是我创建了一个 string() 函数,方法是用逗号分隔值,如下所示
string[] mysamples= gowtham.Split(',');
不知道以后怎么办
等待您的回复?
【问题讨论】:
-
我没有看到你创建的函数。我不太明白你的问题。
-
您已将 字符串 转换为 字符串数组。这些是数据,而不是函数。因此,您的
mysamples对象的类型为string[],它实现了所需的接口IEnumerable<string>。 -
我不认为有什么要补充的:数组实现了
IEnumerable<T>,所以mysamples是已经是IEnumerable<string>了。只需将其包装在一个返回值为IEnumerable<string>的方法中即可。 -
@wRAR 这是函数 IEnumerable
-
@GowthamanSS 不,你没有。