private bool tryCreatePairVals(string[] input, ValTextPairEngine engine) { for (int i = 2; i < input.Length; i += 2) { int val; if (!int.TryParse(input[i], out val)) return false; string pairText = input[i + 1]; engine._pairs.Add(new Tuple<int, string>(val, pairText)); } return true; }
public static void TryCreate(string[] input, out ValTextPairEngine engine) { engine = new ValTextPairEngine(); if (input.Length < 4) { engine._isValid = false; engine._error = "Must input at least 4 params in the form of begin, end, int, text."; return; } if (!int.TryParse(input[0], out engine._begin)) { engine._isValid = false; engine._error = "begin param must be an integer."; return; } if (!int.TryParse(input[1], out engine._end)) { engine._isValid = false; engine._error = "end param must be an integer."; return; } if (engine._begin >= engine._end) { engine._isValid = false; engine._error = "begin param must be larger than end param."; return; } if (!(input.Length % 2 == 0)) { engine._isValid = false; engine._error = "incorrect number of params, after begin and end, must have val/text pairs."; return; } if (!engine.tryCreatePairVals(input, engine)) { engine._isValid = false; engine._error = "val/text pairs must start with integer"; } }