IEnumerable函数c#.net [英] IEnumerable function c# .net
本文介绍了IEnumerable函数c#.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
i在面试中面对这个问题如下?
让我们考虑名为
Hi
i have faced this question in interview as below?
let us consider the string named
string gowtham="test1,test2,test3" ;
i需要转换为IEnumerable字符串函数
i需要输出为
i need to convert in to IEnumerable string function
i need a output to be as
new[] {"test1", "test2","test3" }
我所做的就是我有通过以逗号分隔值来创建一个string()函数,分隔如下:
what i did is i have created a string() function by spliting values by comma seperated as below
string[] mysamples= gowtham.Split('','');
i后不知道如何继续
等待你的回答?
i do not know how to proceed after
waiting for your responses?
推荐答案
你的分裂字符串是一个字符串数组,就像你的例子一样:
Your split string is an array of strings, just as your example is:
string[] arr;
string gowtham="test1,test2,test3";
arr = new[] {"test1", "test2","test3" };
arr = gowtham.Split(',');
产生完全相同的结果。
一系列任何东西都实现了IEnumerable接口,所以没有其他的东西了:
produces exactly the same results.
And an array of anything implements the IEnumerable interface, so there is no further to go:
IEnumerable ie1, ie2;
string gowtham = "test1,test2,test3";
ie1 = new[] { "test1", "test2", "test3" };
ie2 = gowtham.Split(',');
foreach (string s in ie1)
Console.WriteLine(s);
foreach (string s in ie2)
Console.WriteLine(s);
工作得非常好。
这篇关于IEnumerable函数c#.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文