public void findstring(string[, ] str, string st)
for (int i = 0; i < str.GetLength(0); i++)
for (int j = 0; j < str.GetLength(1); j++)
Direction(str, i, j, st, "", "hf", i, j);
Direction(str, i, j, st, "", "hb", i, j);
Direction(str, i, j, st, "", "vu", i, j);
Direction(str, i, j, st, "", "vd", i, j);
Direction(str, i, j, st, "", "tr", i, j);
Direction(str, i, j, st, "", "tl", i, j);
Direction(str, i, j, st, "", "bl", i, j);
Direction(str, i, j, st, "", "br", i, j);
public void Direction(string[, ] str, int x, int y, string st, string newstr, string direction, int start, int end)
Console.WriteLine(start + "," + end);
if (x < 0 || x > (str.GetLength(0) - 1) || y < 0 || y > (str.GetLength(1) - 1) || newstr.Length > st.Length)
Direction(str, x + 0, y + 1, st, newstr + str[x, y], "hf", start, end);
else if (direction == "hb")
Direction(str, x + 0, y - 1, st, newstr + str[x, y], "hb", start, end);
else if (direction == "vu")
Direction(str, x - 1, y + 0, st, newstr + str[x, y], "vu", start, end);
else if (direction == "vd")
Direction(str, x + 1, y + 0, st, newstr + str[x, y], "vd", start, end);
else if (direction == "tr")
Direction(str, x - 1, y + 1, st, newstr + str[x, y], "tr", start, end);
else if (direction == "tl")
Direction(str, x - 1, y - 1, st, newstr + str[x, y], "tl", start, end);
else if (direction == "bl")
Direction(str, x + 1, y - 1, st, newstr + str[x, y], "bl", start, end);
else if (direction == "br")
Direction(str, x + 1, y + 1, st, newstr + str[x, y], "br", start, end);
public static void Main()
string[, ] str = new string[, ]{{"a", "b", "a", "b"}, {"a", "b", "e", "b"}, {"e", "b", "e", "b"}};
Program program = new Program();
program.findstring(str, st);