C# calculate total time worked with TimeSpan
Why does your code pointlessly reinvent the wheel? Microsoft provides methods to convert strings to DateTimes; why not use those instead of your own clunky GetNumberOfMinutes? Or perhaps even better: convert the string directly to a TimeSpan.

On the subject of GetNumberOfMinutes: why even do string sh = result[0].ToString();? The result of spring.Split is an array of strings, why then the need to convert a string to a string? And that's just one of the things that are wrong with that method, there are several more.



The whole flow of your code is IMHO needlessly complex. Why not simply convert each time to a TimeSpan, thus getting a List&lt;TimeSpan&gt;, then calculate the amount of minutes, add those up, and then convert those to a "readable" format?

I don't even understand why you do this: ((int)ts.TotalHours).ToString() + ts.ToString(@"\:mm");. Surely this can be expressed much more elegantly and readable.



On a general note: use proper, self-explanatory names for your variables, and not ts or sh etc.