Pregunta

https://github.com/qntmfred/FooTimestamp

The following program in the AnyCPU build configuration evaluates maxTimestamp as DateTime.MinValue.

public class Foo
{
    public DateTime Timestamp { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        List<Foo> foos = new List<Foo>() { new Foo() { Timestamp = new DateTime(2012, 7, 1) } };
        var maxTimestamp = foos.Any() ? foos.Max(x => x.Timestamp) : new DateTime(2012, 7, 2);
    } // put a breakpoint here - maxTimestamp evaluates to DateTime.MinValue
}

* I've been chasing this bug from a couple different angles since I first posted this, so the comments probably don't make much sense. See the revision history if you want to see it all but I've scrapped most of the original post to focus on what I have now simplified this problem to.

¿Fue útil?

Solución

So it looks like this ended up being a bona fide compiler bug. neat. It's been fixed in .NET 4.5

Bizarre ternary operator behavior in debugger on x64 platform https://connect.microsoft.com/VisualStudio/feedback/details/684202

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top