SHARE
TWEET

Untitled

a guest May 26th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public string ToString() {
  2.     var largest = 0.0;
  3.     for (int x = 0; x < Width; x++) {
  4.         for (int y = 0; y < Width; y++) {
  5.             largest = Math.Max(largest, Grid[x, y]);
  6.         }
  7.     }
  8.  
  9.     var largestLength = Math.Round(largest).ToString().Length;
  10.     var padding = "{0:" + new String('0', largestLength) + ".00}";
  11.     var rowPrefix = "[ ";
  12.     var rowSuffix = " ]";
  13.  
  14.     var formatted = "";
  15.     for (int x = 0; x < Width; x++) {
  16.         formatted += rowPrefix;
  17.         for (int y = 0; y < Width; y++) {
  18.             var format = y < Width - 1 ? padding + " " : padding;
  19.             formatted += String.Format(format, Grid[x, y]);
  20.         }
  21.         formatted += String.Format("{0}{1}", rowSuffix, Environment.NewLine);
  22.     }
  23.     return formatted;
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top