Thank you for finally providing specs that do make sense.
I don't need a StringBuilder, there is no point in accumulating the good characters.
I don't use Peek() as explained before.
public static int GetValueOfFirstNonLetterNonDigit(StreamReader streamReader) {
while (!streamReader.EndOfStream) {
int val = streamReader.Read();
if (!char.IsLetterOrDigit((char)val)) return val;
}
return -1;
}
You still need to fix your test cases, as the expected values don't satisfy the requirements at all.
Further optimization for you to study:
public static int GetValueOfFirstNonLetterNonDigit(StreamReader streamReader) {
while (true) {
int val = streamReader.Read();
if (!char.IsLetterOrDigit((char)val)) return val;
}
}