Ehsan
Ehsan

Reputation: 4464

C# how to add a column of hours which are in string format

working hours of a person in my program will be shown like this:

enter image description here

As they are in string format how can I calculate the total hours of a person?

Upvotes: 0

Views: 112

Answers (2)

Kris Vandermotten
Kris Vandermotten

Reputation: 10201

You indeed need to store the values as TimeSpan instances.

But maybe they are given to you as strings. In that case you can convert them to TimeSpan using TimeSpan.Parse(), see http://msdn.microsoft.com/en-us/library/system.timespan.parse.aspx

Upvotes: 0

Jakub Konecki
Jakub Konecki

Reputation: 46008

You need to store the values as TimeSpans, so you can perform calculations on them, and only convert to strings for display purposes.

Upvotes: 1

Related Questions