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