Thus:
public TimeSpan TempoOtimista { get; set; }
public TimeSpan TempoProvavel { get; set; }
public TimeSpan TempoPessimista { get; set; }
public TimeSpan TempoRevisado { get; set; }
TempoRevisado = new TimeSpan(0, 0,
(int)(TempoOtimista + TempoProvavel + TempoPessimista).TotalSeconds / 3);
Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.
You can say I changed the kind. But now you’re right. DateTime
score a point in time, don’t mark a time spent. This is completely wrong. With wrong data, you can only get wrong results. So the first thing to fix is to change the guy to save a time interval with TimeSpan
.
We can only do it the right way. You could do the math using the wrong way, but when you conceptualize yourself wrong, sooner or later you’ll have problems.
At some point I had to take the amount of seconds because the TimeSpan
does not allow to divide.
Solved the problem? Need more explanation?
– Maniero
@bigown You were very clear, but in my case the best option would be the use of type Datetime . My project looks like this:
var otimista = (atividade.TempoOtimista - atividade.Inicio).TotalDays;
 var provavel = (atividade.TempoProvavel - atividade.Inicio).TotalDays;
 var pessimista = (atividade.TempoPessimista - atividade.Inicio).TotalDays;
– user31040
You can keep using it, but it’s not the best option, it’s wrong. And what you did does not solve what you described in the question. You’re talking about something completely different than what was described.
– Maniero
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero