✗ | string file = "configuration.ini"; | This is a relative path that uses the current working directory. Prone to failure across platforms. |
✗ | string file = TrainFolder + "/configuration.ini"; | This uses a slash as the directory separator. Works on Linux and Mac OS X, but not on Windows. |
✓ | string file = System.IO.Path.Combine(TrainFolder, "configuration.ini"); | This works perfectly on all platforms. |
✓ | string subdirectory = System.IO.Path.Combine(TrainFolder, "subdirectory"); string file = System.IO.Path.Combine(subdirectory, "configuration.ini"); | This works perfectly on all platforms. |
✗ | string[] lines = System.IO.File.ReadAllLines(file); | Uses an unspecified encoding. |
✗ | int number = double.Parse(lines[0]); | Uses an unspecified culture. |
✓ | string[] lines = System.IO.File.ReadAllLines(file, System.Text.Encoding.UTF8); | Uses an explicit encoding. |
✓ | int number; double.TryParse(lines[0], System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out number); | Uses the invariant culture. |
✓ | System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; int number = double.Parse(lines[0]); | Uses the invariant culture. |
API component | Description | Documentation |
---|---|---|
IRuntime | Train plugins | View |