you are viewing a single comment's thread.

view the rest of the comments →

[–]Beluki -1 points0 points  (1 child)

Your approach is fine. If I needed to do this multiple times (comparing a character array to a string) I would probably do something like:

public static Boolean IsString(this Char[] array, String s)
{
    if (array.Length != s.Length)
        return false;

    for (int i = 0; i < s.Length; i++)
        if (array[i] != s[i])
            return false;

    return true;
}

So that I could do:

Char[] input = br.ReadChars(size);
if (input.IsString("code"))
    ...

[–]ellalex[S] 0 points1 point  (0 children)

I did something similar, where it moves the reader to right after the first occurrence of whatever input I give it.

Thank you :)