C# equivalent to Java's charAt()?

ratty picture ratty · Aug 27, 2010 · Viewed 161.3k times · Source

I know we can use the charAt() method in Java get an individual character in a string by specifying its position. Is there an equivalent method in C#?

Answer

Zach picture Zach · Aug 27, 2010

You can index into a string in C# like an array, and you get the character at that index.

Example:

In Java, you would say

str.charAt(8);

In C#, you would say

str[8];