how to return the character which is at the index?

点点圈 提交于 2019-11-27 05:33:43
string s = "hello";
char c = s[1];
// now c == 'e'

See also Substring, to return more than one character.

Do you mean like this

int index = 2;
string s = "hello";
Console.WriteLine(s[index]);

string also implements IEnumberable<char> so you can also enumerate it like this

foreach (char c in s)
    Console.WriteLine(c);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!