문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top