Field methods in C# in the namespace -


so goal of code pick 2 points in grid of numbers , figure out point gets highest value of numbers when counting every other point in grid closest 2 points. while typing code trying use private field variables hold current position of both pointers receive errors field variables have , calls make grid built.

namespace program {  private int xme;  private int yme;  private int zme;  private int xen;  private int yen;  private int zen;  private int dif = 0; public class castles {     public static string process(uint[,] grid)     {         int taxx = 0;         int taxy = 0;          (int = 0; < grid.getlength; i++)         {             for(int j = 0; j < grid[i]; j++)             {                 for(int k = 0; k < grid.getlength; k++)                 {                     for(int l = 0; l < grid[k]; l++)                     {                         if (distance(i, j, k, l) > 3)                         {                             if (grid[i, j] != 0 && grid[k, l] != 0)                             {                             (int m = 0; grid.getlength; m++)                             {                                 (int n = 0; grid[m]; n++)                                 {                                     if (grid[i, j] != grid[m, n] || grid[k, l] != grid[m, n])                                     {                                             if(distance(i,j,m,n) > distance(m, n, k, l))                                             {                                                 taxx = taxx + distance[m, n];                                             }                                             else if(distance(i,j,m,n)< distance(m, n, k, l))                                             {                                                 taxy = taxy + distance[m, n];                                             }                                             else                                             {                                              }                                     }                                 }                             }                             if(taxx - taxy > dif)                                 {                                     xme = i;                                     yme = j;                                     xen = k;                                     yen = l;                                     zme = taxx;                                     zen = taxy;                                     dif = taxx - taxy;                                 }                         }                         }                     }                 }             }         }          return "your castle @ (" + xme + "," + yme + ") earns " + zme + ". nemesis' castle @ (" + xen + "," + yen + ") earns " + zen + ".";     }      public int distance(int x, int y, int a, int b)     {         int c = - x;         int d = b - y;         return math.sqrt(c ^ 2 + d ^ 2);     }      static void main(string[] args)     {         system.console.writeline("");     } } 

}

this first exploration c# simple fix useful

just move definitions of fields inside of class definition...

namespace program {      public class castles {     private int xme;      private int yme;      private int zme;      private int xen;      private int yen;      private int zen;      private int dif = 0;      public static string process(uint[,] grid)     {         int taxx = 0;         int taxy = 0;          (int = 0; < grid.getlength; i++)         {             for(int j = 0; j < grid[i]; j++)             {                 for(int k = 0; k < grid.getlength; k++)                 {                     for(int l = 0; l < grid[k]; l++)                     {                         if (distance(i, j, k, l) > 3)                         {                             if (grid[i, j] != 0 && grid[k, l] != 0)                             {                             (int m = 0; grid.getlength; m++)                             {                                 (int n = 0; grid[m]; n++)                                 {                                     if (grid[i, j] != grid[m, n] || grid[k, l] != grid[m, n])                                     {                                             if(distance(i,j,m,n) > distance(m, n, k, l))                                             {                                                 taxx = taxx + distance[m, n];                                             }                                             else if(distance(i,j,m,n)< distance(m, n, k, l))                                             {                                                 taxy = taxy + distance[m, n];                                             }                                             else                                             {                                              }                                     }                                 }                             }                             if(taxx - taxy > dif)                                 {                                     xme = i;                                     yme = j;                                     xen = k;                                     yen = l;                                     zme = taxx;                                     zen = taxy;                                     dif = taxx - taxy;                                 }                         }                         }                     }                 }             }         }          return "your castle @ (" + xme + "," + yme + ") earns " + zme + ". nemesis' castle @ (" + xen + "," + yen + ") earns " + zen + ".";     }      public int distance(int x, int y, int a, int b)     {         int c = - x;         int d = b - y;         return math.sqrt(c ^ 2 + d ^ 2);     }      static void main(string[] args)     {         system.console.writeline("");     } } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -