Terminal methods to use
In Sequence and Data, we were able to use a number of methods from the .NET System libraries and SplashKit in order to produce outputs and read values from the user. Now that we have control flow, there are a number of additional methods that you can use to help with your projects.
Terminal Methods
In addition to WriteLine
, Write
, ReadLine
, and the convert methods we will now need ways to check if data provided has the right format. The .NET library doesn’t have the best
public static bool SplashKit.IsDouble(string text);public static bool SplashKit.IsInteger(string text);
These methods will allow you to test if a string can be converted to an integer or a double. You can use these to perform simple validations, by using this as the condition in a loop. For example, the following validates the entry of a double value.
using static SplashKitSDK.SplashKit;using static System.Convert;
string line;double value;
Write("Please enter a number: ");line = ReadLine();while (!IsDouble(line)){ WriteLine($"Sorry, I cannot convert {line} to a number."); Write("Please enter a number: "); line = ReadLine();}value = ToDouble(line);
WriteLine($"Thanks you I got {value}");