static void Initialize(int[,,] s) { for (int i = s.GetLowerBound(0); i <= s.GetUpperBound(0); i++) { for (int j = s.GetLowerBound(1); j <= s.GetUpperBound(1); j++) { for (int k = s.GetLowerBound(2); k <= s.GetUpperBound(2); k++) { s[i, j, k] = (2 * i) - (3 * j) + (5 * k); } } } }
static bool VerifyCopy(int[,,] s, int[,,] d) { for (int i = s.GetLowerBound(0); i <= s.GetUpperBound(0); i++) { for (int j = s.GetLowerBound(1); j <= s.GetUpperBound(1); j++) { for (int k = s.GetLowerBound(2); k <= s.GetUpperBound(2); k++) { if (s[i, j, k] != d[i, j, k]) { return(false); } } } } return(true); }
private static void ReplacePos(ref int[,,] array) { for (int i = array.GetLowerBound(0); i <= array.GetUpperBound(0); i++) { for (int j = array.GetLowerBound(1); j <= array.GetUpperBound(1); j++) { for (int k = array.GetLowerBound(2); k <= array.GetUpperBound(2); k++) { if (array[i, j, k] > 0) { array[i, j, k] = 0; } Console.Write($"{array[i, j, k]} "); } Console.WriteLine(); } } }
public void meshCopy(int[,,] world, GameObject [,,] worldObjects, GameObject Go) { int GOcnt = 0; for (int x = world.GetLowerBound(0); x < world.GetUpperBound(0); x++) { for (int y = world.GetLowerBound(1); y < world.GetUpperBound(1); y++) { for (int z = world.GetLowerBound(2); z < world.GetUpperBound(2); z++) { if (world[x, y, z] == 1) { worldObjects[x, y, z] = (GameObject)Instantiate(Go, new Vector3(x, y, z), new Quaternion(0.0f, 0.0f, 0.0f, 0.0f)); GOcnt = GOcnt + 1; worldObjects[x, y, z].name = "GOgen_" + GOcnt; } } } } }
static bool Bench(int loop, int[,,] s, int[,,] d) { Initialize(s); for (; loop != 0; loop--) { for (int i = s.GetLowerBound(0); i <= s.GetUpperBound(0); i++) { for (int j = s.GetLowerBound(1); j <= s.GetUpperBound(1); j++) { for (int k = s.GetLowerBound(2); k <= s.GetUpperBound(2); k++) { d[i, j, k] = s[i, j, k]; } } } } bool result = VerifyCopy(s, d); return(result); }
static void ArrayManuplate() { //int i = 10, j=20; //Pointers(ref i,ref j); var ay = new Book[4];// {1, 2, 3, 4}; ay[1] = new MyBook("a", "b", 120); ay[3] = ay[1]; int[, ,] arr = { { { 1, 2, 3 }, { 4, 5, 6 } }, { { 11, 12, 13 }, { 14, 15, 16 } } }; int rank = arr.Length;//.Rank; int lb = arr.GetLowerBound(0); int ub = arr.GetUpperBound(0); for (int k = 0; k < 2; k++) { for (int l = 0; l < 2; l++) { for (int i = 0; i < 3; i++) { arr[k, l, i] = k + l + i; } } } int[] arrr = { 11, 2, 3, 4 }; //var ar=Array.Find(arrr, a => a > 2); Array.Sort(arrr, new Comp()); //Converter<int, string> con = null; //Array.ConvertAll<int,string>(arrr, con); string[] arrstr = { "abebe", "beso", "bela" }; Array.Clear(arrstr, 0, arrstr.Length); var a = Array.CreateInstance(typeof(string), 3, 3); //Array.ForEach(arrr); //Array.Resize(ref arrr,2); Array.Reverse(arrr); IList <int> arList = new List <int>(); arList = arrr.ToList(); var arLi = arList.Select(l => l + 3).ToList(); //return new int[0]; //return new[] { 1, 2, 3, 4 }; //Hashtable ht=new Hashtable(); //Dictionary<string,int> dict=new Dictionary<string, int>(10); }
static void Main() { int[,] twoDim = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }; for (int i = twoDim.GetLowerBound(0); i <= twoDim.GetUpperBound(0); ++i) { for (int j = twoDim.GetLowerBound(1); j <= twoDim.GetUpperBound(1); ++j) { Console.WriteLine(twoDim[i, j]); } } //https://msdn.microsoft.com/tr-tr/library/system.array.getlowerbound(v=vs.110).aspx // Create a one-dimensional integer array. int[] integers = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }; // Get the upper and lower bound of the array. int upper = integers.GetUpperBound(0); int lower = integers.GetLowerBound(0); Console.WriteLine("Elements from index {0} to {1}:", lower, upper); // Iterate the array. for (int ctr = lower; ctr <= upper; ctr++) { Console.Write("{0}{1}{2}", ctr == lower ? " " : "", integers[ctr], ctr < upper ? ", " : Environment.NewLine); } Console.WriteLine(); // Two-dimensional array. // Create a two-dimensional integer array. int[,] integers2d = { { 2, 4 }, { 3, 9 }, { 4, 16 }, { 5, 25 }, { 6, 36 }, { 7, 49 }, { 8, 64 }, { 9, 81 } }; // Get the number of dimensions. int rank = integers2d.Rank; Console.WriteLine("Number of dimensions: {0}", rank); for (int ctr = 0; ctr < integers2d.Rank - 1; ctr++) { Console.WriteLine(" Dimension {0}: from {1} to {2}", ctr, integers2d.GetLowerBound(ctr), integers2d.GetUpperBound(ctr)); } // Iterate the 2-dimensional array and display its values. Console.WriteLine(" Values of array elements:"); for (int outer = integers2d.GetLowerBound(0); outer <= integers2d.GetUpperBound(0); outer++) { for (int inner = integers2d.GetLowerBound(1); inner <= integers2d.GetUpperBound(1); inner++) { Console.WriteLine(" {3}{0}, {1}{4} = {2}", outer, inner, integers2d.GetValue(outer, inner), "{", "}"); } } Console.WriteLine(" {4}{0}, {1}, {2}{5} = {3}", 0, 1, 2, 3, "{", "}"); // Three-dimensional array. int[, ,] integer3d = { { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }, { { 10, 11, 12 }, { 13, 14, 15 }, { 16, 17, 18 } }, { { 19, 20, 21 }, { 22, 23, 24 }, { 25, 26, 27 } } }; // Get the number of dimensions rank = integer3d.Rank; Console.WriteLine("Number of dimensions: {0}", rank); for (int ctr = 0; ctr < integer3d.Rank - 1; ctr++) { Console.WriteLine(" Dimension {0}: from {1} to {2}", ctr, integer3d.GetLowerBound(ctr), integer3d.GetUpperBound(ctr)); } for (int outer = integer3d.GetLowerBound(0); outer <= integer3d.GetUpperBound(0); outer++) { for (int inner = integer3d.GetLowerBound(1); inner <= integer3d.GetUpperBound(1); inner++) { for (int innerr = integer3d.GetLowerBound(2); innerr <= integer3d.GetUpperBound(2); innerr++) { Console.WriteLine(" {4}{0}, {1}, {2}{5} = {3}", outer, inner, innerr, integer3d.GetValue(outer, inner, innerr), "{", "}"); } } } Console.ReadLine(); }