fork download
  1. using System;
  2.  
  3. namespace Project
  4. {
  5. class Program
  6. {
  7. public static void Main()
  8. {
  9. World world = new World(10, 8);
  10. world[1, 5] = 5;
  11. PrintWorld(world);
  12. Console.ReadKey();
  13. }
  14.  
  15. public static void PrintWorld(World world)
  16. {
  17. for (int y = 0; y < world.Height; y++)
  18. {
  19. for (int x = 0; x < world.Width; x++)
  20. Console.Write("{0} ", world[x, y]);
  21. Console.WriteLine();
  22. }
  23. }
  24.  
  25. public class World
  26. {
  27. private int[,] world;
  28. public int Width => world.GetLength(1);
  29. public int Height => world.GetLength(0);
  30.  
  31. public World(int width, int height, int defaultValue = 0)
  32. {
  33. world = new int[height, width];
  34.  
  35. for (int y = 0; y < height; y++)
  36. for (int x = 0; x < width; x++)
  37. world[y, x] = defaultValue;
  38. }
  39.  
  40. public bool IsCoordinatesCorrect(int x, int y)
  41. {
  42. return x >= 0 && x < Width
  43. && y >= 0 && y < Height;
  44. }
  45.  
  46. public int this[int x, int y]
  47. {
  48. get => world[y, x];
  49. set => world[y, x] = value;
  50. }
  51. }
  52. }
  53. }
Success #stdin #stdout 0.02s 16020KB
stdin
Standard input is empty
stdout
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 5 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0