Miscellaneous
Timing execution
DateTime startTime = DateTime.Now;
// Perform a task, for example
Scenario scenario = Toolbox.CalculateEnergy();
// Find the elapsed time in seconds (other units available)
double elapsedSeconds = (DateTime.Now - startTime).TotalSeconds;
Convert Formats
C# Recommends using the functions available in Convert to covert between data formats. There are functions for all data type conversions possible.
// Reading an EPSG code from Excel, converting it to unsigned integer (uint)
// and getting the corresponding projection.
var epsgFromExcel =
Toolbox.ReadRangeFromExcel
(@"MyExcelFile.xlsx",
"Sheet1",
"A1");
uint epsgCode = Convert.ToUInt32(epsgFromExcel.First());
Projection projection = Toolbox.GetProjectionFromEpsgCode(epsgCode);
// Converting a string to double
string str = "5.5";
double dbl = Convert.ToDouble(str);
// Converting back to string, all objects have a ToString() method that can be called.
dbl = dbl + 7.1;
string st2 = dbl.ToString();
// Nevertheless, Convert also has a convertion to string.
string str3 = Convert.ToString(dbl);