Search code examples
c#.netstringindexof

How can I get a character in a string by index?


I know that I can return the index of a particular character of a string with the indexof() function, but how can I return the character at a particular index?


Solution

  • string s = "hello";
    char c = s[1];
    // now c == 'e'
    

    See also Substring, to return more than one character.