C# Programming Questions – String Input to Number Conversion

Use these questions to test associates on handling string inputs and converting them into numbers safely in C#.

  1. Input: "42" – Convert this straightforward string into an integer.
  2. Input: "12.34" – Transform this string into a double precision number.
  3. Input: "1 2 3 4" – Split by spaces and turn each piece into integers.
  4. Input: "9.5 8.3 7.1" – Break it apart and convert these to a list of doubles.
  5. Input: "Fifty" – Validate that this string is not a number at all.
  6. Input: "15.7abc" – Extract just the numeric portion.
  7. Input: "999999999" – Convert this large number into a long.
  8. Input: "0xFF" – Convert this hex string into an integer.
  9. Input: "3E+3" – Convert this scientific notation into a double.
  10. Input: "42.5 36.1 -12" – Handle positive and negative numbers from a string.
  11. Input: " 75 " – Trim spaces and convert the result to an integer.
  12. Input: "3.14.15" – Detect and report that this is not a valid number.
  13. Input: "1.000.000" – Handle formatting where dots are used as group separators.
  14. Input: "1,234.56" – Convert a number formatted with commas and a decimal.
  15. Input: "(123)" – Treat this as a negative number.
  16. Input: "12:30" – Convert time (hours and minutes) into total minutes.
  17. Input: "$1,500.75" – Extract and convert the numeric portion.
  18. Input: "8 16 32 bits" – Extract only the numbers and sum them.
  19. Input: "0b1011" – Convert a binary string to an integer.
  20. Input: "2,000 apples and 3,500 oranges" – Extract both numbers and add them together.