////////////////////////////////////////////////// /// void changeCounter(object sender, KeyEventArgs e) { var obj = ((dynamic)sender).Name; dynamic[,] arr = { { tbxX, tbxY }, { tbxGotoX, tbxGotoY } }; int n = 0; for (int i = 0; i < arr.GetLength(0); i++) { for (int j = 0; j < arr.GetLength(1); j++) { if (arr[i, j].Name == obj) { n = i; } } } if (e.KeyCode == Keys.Right) { arr[n, 0].Text = (int.Parse(arr[n, 0].Text) + 1).ToString(); } else if (e.KeyCode == Keys.Left) { arr[n, 0].Text = (int.Parse(arr[n, 0].Text) - 1).ToString(); } else if (e.KeyCode == Keys.Up) { arr[n, 1].Text = (int.Parse(arr[n, 1].Text) - 1).ToString(); } else if (e.KeyCode == Keys.Down) { arr[n, 1].Text = (int.Parse(arr[n, 1].Text) + 1).ToString(); } }
/* public static MathNet.Numerics.LinearAlgebra.Double.DenseMatrix matrix(string str) * { * if(str.Contains("{")&& str.Contains("}")) * return MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.OfArray(Accord.Math.Matrix.Parse(str, Accord.Math.CSharpMatrixFormatProvider.InvariantCulture)); * else if (str.Contains("[") && str.Contains("]")) * return MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.OfArray(Accord.Math.Matrix.Parse(str, Accord.Math.OctaveMatrixFormatProvider.InvariantCulture)); * else * return MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.OfArray(Accord.Math.Matrix.Parse(str, Accord.Math.DefaultMatrixFormatProvider.InvariantCulture)); * }*/ public static dynamic matrix(dynamic[,] array) //TODO: test it { for (int j = 0; j < array.GetLength(0); j++) { for (int k = 0; k < array.GetLength(1); k++) { //writeln(array[0,0].GetType()); if (array[j, k] is System.Numerics.Complex) { var narray = new System.Numerics.Complex[array.GetLength(0), array.GetLength(1)]; for (int j2 = 0; j2 < array.GetLength(0); j2++) { for (int k2 = 0; k2 < array.GetLength(1); k2++) { narray[j2, k2] = (System.Numerics.Complex)array[j2, k2]; } } return(MathNet.Numerics.LinearAlgebra.Complex.DenseMatrix.OfArray(narray)); } } } var narray2 = new double[array.GetLength(0), array.GetLength(1)]; for (int j2 = 0; j2 < array.GetLength(0); j2++) { for (int k2 = 0; k2 < array.GetLength(1); k2++) { narray2[j2, k2] = (double)array[j2, k2]; } } return(MathNet.Numerics.LinearAlgebra.Double.DenseMatrix.OfArray(narray2)); }
private void ascbtn_Click(object sender, EventArgs e) { Sort(); dataGridView1.Rows.Clear(); for (int i = 0; i < data.GetLength(0); i++) { dataGridView1.Rows.Add(data[i, 0], data[i, 1], data[i, 2], data[i, 3]); } }
static void PrintArray(dynamic[,] array) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { Console.Write(array[i, j] + "\t"); } Console.WriteLine(); } }
static void TransposeMatrix(dynamic[,] array) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = i + 1; j < array.GetLength(1); j++) { var temp = array[i, j]; array[i, j] = array[j, i]; array[j, i] = temp; } } }
private static void Sort() { dynamic prodatax = File.ReadAllLines("ProductData.txt"), prodatay = prodatax[0].Split(','); data = new dynamic[prodatax.Length, prodatay.Length]; for (int i = 0; i < prodatax.Length; i++) { prodatay = prodatax[i].Split(','); for (int j = 0; j < prodatay.Length; j++) { if (j == 1) { data[i, j] = prodatay[j]; } else if (j == 0) { data[i, 0] = Convert.ToInt64(prodatay[j]); } else if (j == 2) { data[i, 2] = Convert.ToInt64(prodatay[j]); } else { data[i, 3] = Convert.ToInt64(prodatay[j]); } } } for (int i = 0; i < data.GetLength(0) - 1; i++) { int minIdx = i; for (int j = i + 1; j < data.GetLength(0); j++) { if (compData(data[minIdx, dataindexA], data[j, dataindexA], data[j, dataindexA].GetType())) { minIdx = j; } } if (minIdx != i) //Swap { for (int j = 0; j < data.GetLength(1); j++) { dynamic[,] temp = new dynamic[data.GetLength(0), data.GetLength(1)]; temp[i, j] = data[i, j]; data[i, j] = data[minIdx, j]; data[minIdx, j] = temp[i, j]; } } } }
static void ThirteenthArea(dynamic[,] array) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if (!((i >= j) && (j >= -i + array.GetLength(0) - 1))) { array[i, j] = 1; } } } }
private int getIndex(string colName) { int colCount = arrFeed.GetLength(1); for (int i = 0; i < colCount; i++) { if (arrFeed[0, i].Key == colName) { return(i); } } return(0); }
static void FillWithRandom(dynamic[,] array) { Random rnd = new Random(); for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if (array[i, j] != null) { array[i, j] = rnd.Next(300); } } } }
static void FillWithRandomEngLetters(dynamic[,] array) { Random rnd = new Random(); for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if (array[i, j] != null) { array[i, j] = (char)rnd.Next('a', 'z' + 1); } } } }
static void FifthArea(dynamic[,] array) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if ((i >= j) && (j >= -i + array.GetLength(0) - 1)) { array[i, j] = ' '; } if ((j >= i) && (j < -i + array.GetLength(0))) { array[i, j] = ' '; } } } }
static bool ContainsSymbol(dynamic[,] array, char SymbolToFind) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if (array[i, j] != null) { if (array[i, j] == SymbolToFind) { return(true); } } } } return(false); }
//Convert rectangular array to jagged array public static dynamic[][] ToJagged(this dynamic[,] array) { int height = array.GetLength(0); int width = array.GetLength(1); dynamic[][] jagged = new dynamic[height][]; for (int i = 0; i < height; i++) { dynamic[] row = new dynamic[width]; for (int j = 0; j < width; j++) { row[j] = array[i, j]; } jagged[i] = row; } return(jagged); }
static dynamic FindMax(dynamic[,] array) { int max = array[0, 0]; for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if (array[i, j] != null) { if (array[i, j] > max) { max = array[i, j]; } } } } return(max); }
static dynamic FindMin(dynamic[,] array) { int min = array[0, 0]; for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if (array[i, j] != null) { if (array[i, j] < min) { min = array[i, j]; } } } } return(min); }
static void FirstArea(dynamic[,] array) { for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j <= i; j++) { array[i, j] = ' '; } } }
private void Connection_byDistinct(object sender, EventArgs e) { var obj = ((dynamic)sender).Name; dynamic[,] arr = { { gbxRobot, tbxIPRobot, tbxPortRobot }, { gbxBS, tbxIPBS, tbxPortBS } }; int n = 0; for (int i = 0; i < arr.GetLength(0); i++) { for (int j = 0; j < arr.GetLength(1); j++) { if (arr[i, j].Name == obj) { n = i; } } } if ((!String.IsNullOrWhiteSpace(arr[n, 1].Text)) && (!String.IsNullOrWhiteSpace(arr[n, 2].Text))) { new Thread(objs => reqConnect(arr[n, 1].Text, arr[n, 2].Text, arr[n, 0].Text)).Start(); } }
static void FillWithOdd(dynamic[,] array, int start, int end) { if (start % 2 == 0) { start++; } for (int i = 0; i < array.GetLength(0); i++) { for (int j = 0; j < array.GetLength(1); j++) { if (array[i, j] != null) { array[i, j] = start; start += 2; } } if (start > end) { break; } } }
private static void Drive() { /// Drive in Array dynamic datai = File.ReadAllLines(path), dataj = datai[0].Split('#'); data = new dynamic[datai.Length, dataj.Length]; for (int i = 0; i < datai.Length; i++) { dataj = datai[i].Split('#'); for (int j = 0; j < dataj.Length; j++) { if (j != 4) { data[i, j] = dataj[j]; } else { data[i, j] = DateTime.Parse(dataj[j]); } } } if (valSortM == 1) { BubbleS(); } else if (valSortM == 2) { SelectionS(); } else if (valSortM == 3) { InsertionS(); } else if (valSortM == 4) { ShellS(); } else if (valSortM == 5) { QuickS(0, data.GetLength(0) - 1); } }
static void RotateMatrix(dynamic[,] oldMatrix) { dynamic[,] newMatrix = new dynamic[oldMatrix.GetLength(1), oldMatrix.GetLength(0)]; int newColumn, newRow = 0; for (int oldColumn = oldMatrix.GetLength(1) - 1; oldColumn >= 0; oldColumn--) { newColumn = 0; for (int oldRow = 0; oldRow < oldMatrix.GetLength(0); oldRow++) { newMatrix[newRow, newColumn] = oldMatrix[oldRow, oldColumn]; newColumn++; } newRow++; } for (int i = 0; i < oldMatrix.GetLength(0); i++) { for (int j = 0; j < oldMatrix.GetLength(1); j++) { oldMatrix[i, j] = newMatrix[i, j]; } } }
private static void Swap(int x, int y) { for (int j = 0; j < data.GetLength(1); j++) { dynamic temp = data[x, j]; data[x, j] = data[y, j]; data[y, j] = temp; } }
internal static List <T> ConvertArrayToList <T>(dynamic[,] arrData, Dictionary <PropertyInfo, int> propColIndex = null, Dictionary <PropertyInfo, string> propColFormat = null) { List <T> result = null; if (arrData == null) { return(result); } if (arrData.GetUpperBound(0) < arrData.GetLowerBound(0)) { return(result); } if (arrData.Rank != 2) { throw new InvalidOperationException("arrData.Rank != 2 ReadData"); } result = new List <T>(); if (propColIndex != null && propColIndex.Count > 0) { for (int i = arrData.GetLowerBound(0); i <= arrData.GetUpperBound(0); i++) { T obj = Activator.CreateInstance <T>(); foreach (KeyValuePair <PropertyInfo, int> item in propColIndex) { PropertyInfo prop = item.Key; int colNum = item.Value; object colValue = arrData[i, colNum]; if (colValue != null && prop.PropertyType != colValue.GetType()) { object val = null; if (colValue.GetType() == typeof(string) && prop.PropertyType == typeof(DateTime)) { string colFormat = propColFormat != null && propColFormat.ContainsKey(prop) ? propColFormat[prop] : string.Empty; val = string.IsNullOrEmpty(colFormat) ? DateTime.Parse((string)colValue) : DateTime.ParseExact((string)colValue, colFormat, System.Globalization.CultureInfo.InvariantCulture); } else { val = Convert.ChangeType(colValue, prop.PropertyType); } prop.SetValue(obj, val); } else { prop.SetValue(obj, colValue); } } } } else { PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance); int maxCol = Math.Min(arrData.GetLength(1), props.Length); for (int i = arrData.GetLowerBound(0); i <= arrData.GetUpperBound(0); i++) { T obj = Activator.CreateInstance <T>(); for (int j = 0; j < maxCol; j++) { object colValue = arrData[i, j + 1]; if (colValue != null) { if (colValue.GetType() != props[j].PropertyType) { object val = Convert.ChangeType(colValue, props[j].PropertyType); props[j].SetValue(obj, val); } else { props[j].SetValue(obj, colValue); } } else { props[j].SetValue(obj, null); } } } } return(result); }
private void App_SheetChange(object Sh, Range Target) { if (!IsLoad() || !IsTable(app.ActiveSheet)) { return; } if (Target.Value != null) { if (Target.Value is object[]) { dynamic[] rangeArray = Target.Value; for (int ri = 0; ri < rangeArray.Length; ri++) { if (rangeArray[ri] == null) { } } } if (Target.Value is object[, ]) { dynamic[,] rangeArray = Target.Value; for (int ri = 1; ri <= rangeArray.GetLength(0); ri++) { for (int ci = 1; ci <= rangeArray.GetLength(1); ci++) { int a = rangeArray.GetLength(1); if (rangeArray[ri, ci] == null) { } } } } if (Target.Value is string) { Target.Font.Name = "Microsoft YaHei UI"; } } if (Target.Row == 1) { Target.Font.Color = Color.Gray; } if (Target.Row == _RowDescription) { Target.Font.Color = Color.Green; } if (Target.Row == _RowType) { Target.Font.Color = Blue; Target.Font.Bold = true; string targetType = ((Range)app.Cells[_RowType, Target.Column]).Value; if (targetType == string.Empty || targetType == null) { targetType = "string"; } targetType = targetType.Trim().ToLower(); if (targetType == "int" || targetType == "int32" || targetType == "integer") { ((Range)app.Columns[Target.Column]).NumberFormatLocal = "0"; } else if (targetType == "float" || targetType == "single") { } else { ((Range)app.Columns[Target.Column]).NumberFormatLocal = "@"; } } if (Target.Row == _RowLenOrExp) { Target.Font.Color = Orange; Target.NumberFormatLocal = "@"; } if (Target.Row == _RowField) { int LastColumn = app.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Column; //MessageBox.Show(LastColumn.ToString()); if (Target.Text == "") { Target.Font.ColorIndex = 0; Target.Interior.ColorIndex = 0; } else { Target.Font.Color = Color.White; Target.Interior.Color = Blue; } } if (Target.Row > _RowField) { DataRegion(Sh, Target); } }