I'm trying to make my particles fade in my application using the alpha argument of the Color.FromArgb method but my math won't work because I have a nullable DateTime variable and the error it gives me is 'System.Nullable<System.TimeSpan>' does not contain a definition for 'TotalMilliseconds' and no extension method 'TotalMilliseconds' accepting a first argument of type 'System.Nullable<System.TimeSpan>' could be found (are you missing a using directive or an assembly reference?). Below is the code line that is throwing this error, can anyone help me get around this?

// Declaration of the variable
private DateTime? ParticleBirth;

// Error Line
double TotalLife = (DateTime.Now - ParticleBirth).TotalMilliseconds;

Thanks,
Jamie

Since the DateTime is nullable, you should check if it is null before your TotalLife calculation, then cast it into a DateTime.

I solved the problem:

// Declaration of the variable
private DateTime? ParticleBirth;

// Error Line
double TotalLife = (DateTime.Now - ParticleBirth.Value).TotalMilliseconds;

The point of a nullable time is so that I can achieve handling for if it's null, then set it to the birth time. Because the particles are not born at runtime, they are born on an event that can be triggered multiple times in a row. Thanks for the help anyways.

This question has already been answered. Start a new discussion instead.