I have a constructor method similar to this:
public class Foo
{
public Foo (DateTime? startFrom)
{
_startFrom = startFrom;
}
}
And I am calling this constructor method like this:
var context = new Foo(new DateTime(2012, 7, 15, 11, 2, 10, 2)); // 2 miliseconds
But when I debug it, I find that the 002 milliseconds are set to 000 when passed to the default constructor which is a Nullable DateTime parameter.
Is it normal that I lose the milliseconds of a DateTime when I pass it as a parameter to a method which takes Nullable DateTime?
No, it’s not normal – and I strongly suspect that this is a diagnostics issue.
When you debug through the code, I suspect you’re using a watch window which happens not to display the milliseconds in its string representation. Expand the variable itself and I’m sure you’ll see the milliseconds component is preserved.
(If that’s not the case, please provide a short but complete program which demonstrates the problem, rather than just the snippet you’ve shown.)