K. Turek K. Turek - 3 months ago 10
C# Question

Compare times repesented as string with colon

I have string with colon, for example

"10:28"
and I want to convert this to int variable. I was looking for solution in
System.Globalization.NumberStyles
but I don't find anything. I need that to compare two different times. Maybe is there any better way to do this?

Answer
var Str1 = "10:45";
var Str2 = "10:28";

if(TimeSpan.Parse(Str1) > TimeSpan.Parse(Str2) )
  ...