I would like to create a 2D matrix in C#.
I have the following example code in C++
https://www.geeksforgeeks.org/search-a-word-in-a-2d-grid-of-characters/
I would like to init the matrix like they did in C++
int main()
{
char grid[R][C] = {"GEEKSFORGEEKS",
"GEEKSQUIZGEEK",
"IDEQAPRACTICE"
};
patternSearch(grid, "GEEKS");
....
Here is my code in C#
List<string> rows = new List<string> {"GEEKSFORGEEKS", "GEEKSQUIZGEEK", "IDEQAPRACTICE"};
char[,] grid = new char[rows.Count, rows[0].Length];
for (int r = 0; r < rows.Count; r++)
{
char[] charArray = rows[r].ToCharArray();
for (int c = 0; c < charArray.Length; c++)
{
grid[r, c] = charArray[c];
}
}
Is there a way to init the matrix like in c++? converting string to char array, or this is done easily in c++ because we can cast and manage the memory differently?