Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I convert these Java code pieces to C#?

   public String getRawMaze() {
    StringBuilder sb = new StringBuilder();
    for (int[] row : maze) {
        sb.append(Arrays.toString(row) + "\n");
    }
    return sb.toString();
}

How can I convert this code to C#?
Maze is:

private int[][] maze;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Adapt to C# naming conventions (methods start with upper letter), replace Arrays.toString by string.Join and change the syntax for foreach loop:

public string GetRawMaze()
{
    StringBuilder sb = new StringBuilder();
    foreach (int[] row in maze)
    {
        sb.Append("[" + string.Join(", ",row) + "]\n");
    }
    return sb.ToString();
}

Online-demo: https://dotnetfiddle.net/IqFYhJ

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading