public static bool TryParseInt(string str, out ScalarValue result) { result = null; // default the out value to null int val; if (int.TryParse(str, out val)) { result = new ScalarIntValue(val); return true; } return false; }