fork(2) 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, 10);
  10.  
  11. for (int y = 0; y < 10; y++)
  12. {
  13. for (int x = 0; x < 10; x++)
  14. Console.Write("{0} ", world.Get(x, y));
  15. Console.WriteLine();
  16. }
  17. Console.ReadKey();
  18. }
  19. }
  20.  
  21. class World
  22. {
  23. private int[,] world;
  24. public int Width { get; private set; }
  25. public int Height { get; private set; }
  26.  
  27. public World(int width, int height, int defaultValue = 0)
  28. {
  29. world = new int[height, width];
  30. Width = width;
  31. Height = height;
  32.  
  33. for (int y = 0; y < height; y++)
  34. for (int x = 0; x < width; x++)
  35. Set(x, y, defaultValue);
  36. }
  37.  
  38. public bool Check(int x, int y)
  39. {
  40. return x >= 0 && x < Width
  41. && y >= 0 && y < Height;
  42. }
  43.  
  44. public int Get(int x, int y)
  45. {
  46. if (!Check(x, y))
  47. throw new Exception($"Out of bounds (x: {x}, y: {y})");
  48.  
  49. return world[y, x];
  50. }
  51.  
  52. public int Set(int x, int y, int value)
  53. {
  54. if (!Check(x, y))
  55. throw new Exception($"Out of bounds (x: {x}, y: {y})");
  56.  
  57. return world[y, x];
  58. }
  59. }
  60. }
Success #stdin #stdout 0.02s 15804KB
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 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