Now, I wanted to convert the above in the Timespan. My below code gives error because I have 5 digits after "." and I have 6 f (.ffffff) in the timespan format.
Stack Trace:[System.FormatException: Input string was not in a correct format.] at System.Globalization.TimeSpanParse.TryParseByFormat(String input, String format, TimeSpanStyles styles, TimeSpanResult& result) at System.Globalization.TimeSpanParse.TryParseExactTimeSpan(String input, String format, IFormatProvider formatProvider, TimeSpanStyles styles, TimeSpanResult& result) at System.Globalization.TimeSpanParse.ParseExact(String input, String format, IFormatProvider formatProvider, TimeSpanStyles styles) at System.TimeSpan.ParseExact(String input, String format, IFormatProvider formatProvider, TimeSpanStyles styles) at Program.Main() :line 9
Edit: I want to reinforce Andy's comment and say that since C# 7.0 there's been a tiny improvement to the output parameter feature which prevents code smell. Basically his code could be refactored to include the variable type inline the out to prevent redundant declaration.
Edit: I want to reinforce Andy's comment and say that since C# 7.0 there's been a tiny improvement to the output parameter feature which prevents code smell. Basically his code could be refactored to include the variable type inline the out to prevent redundant declaration.
Open in new window