Hello, I am trying to write a method, that checks if a string is isomorphic and returns true or false. In line 10 in the code posted below, I get a System.OutOfRangeException and I just can't figure out what I am doing false.
C#:
public static bool IsIsomorphic(string s, string t)
{
bool isomorphic = false;
string endstring = "";
if (t.Length != s.Length)
return false;
for (int i = 1; i <= s.Length; i++)
{
if (s.IndexOf(s[i]) != s.LastIndexOf(s, i) && t[s.IndexOf(s[i])] == t[s.LastIndexOf(s, i)] || s.IndexOf(s[i]) == s.LastIndexOf(s, i))
{
endstring += s[i];
}
}
if (endstring.Length == s.Length)
isomorphic = true;
else
isomorphic = false;
return isomorphic;
}
static void Main(string[] args)
{
Console.WriteLine(IsIsomorphic("siinger", "solnaer"));
Console.ReadKey();
}