C# equivalent to Javas charAt()?

C# equivalent to Javas charAt()?

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];
string sample = ratty;
Console.WriteLine(sample[0]);

And


Console.WriteLine(sample.Chars(0));
Reference: http://msdn.microsoft.com/en-us/library/system.string.chars%28v=VS.71%29.aspx

The above is same as using indexers in c#.

C# equivalent to Javas charAt()?

you can use LINQ

string abc = abc;
char getresult = abc.Where((item, index) => index == 2).Single();

Leave a Reply

Your email address will not be published.