-1

In short, something like this:

private void checkMethod()
{
    if (textBoxCode.Text.Contains("a").Position(Char.3)))
    {
        // Then do this...
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 2
    Does this answer your question? [How can I get a character in a string by index?](https://stackoverflow.com/questions/2416894/how-can-i-get-a-character-in-a-string-by-index) – Sinatr Sep 23 '20 at 07:21

1 Answers1

1

If I understand your pseudo code completely. There are many ways, however I guess you could do something like

if(textBoxCode.Text?.Length >= 3 && textBoxCode.Text[2] == 'a')

Calling textBoxCode.Text?.Length is basic fault tolerance


Or you could use ElementAtOrDefault, which does all the above

Returns the element at a specified index in a sequence or a default value if the index is out of range.

if(textBoxCode.Text?.ElementAtOrDefault(2) == 'a')
TheGeneral
  • 79,002
  • 9
  • 103
  • 141