1

我认为当您将断点拖放到不同的分支并且使用某种类型的 LINQ 查询时,我在 Visual Studio 中发现了一个错误。如果您在下面的“if (x)”上放置断点并将执行行拖到 else 分支,则代码将在“test2”集合的初始化/构造函数上失败。

我之前在 LINQ 中使用过这种“double from”语法来进行连接,我认为这是一种公认​​的做法——不确定是否有一个术语。

无论如何,其他人可以确认这种奇怪的调试行为吗?

    public class TestEntity
    {
        public int TestID { get; set; }
        public string Test { get; set; }
    }

    public class Test2Entity
    {
        public int Test2ID { get; set; }
        public string Test2 { get; set; }
    }

    private void button1_Click(object sender, EventArgs e)
    {
            bool x = Calc();

            if (x) //breakpoint here
            {
                int y = 1;
            }
            else
            {
                System.Collections.ObjectModel.Collection<TestEntity> test = new System.Collections.ObjectModel.Collection<TestEntity>();
                System.Collections.ObjectModel.Collection<Test2Entity> test2 = new System.Collections.ObjectModel.Collection<Test2Entity>(); // fails here

                var z = from t in test
                        from t2 in test2
                        select t.TestID;
            }
        }

        private bool Calc()
        {
            return true;
        }
4

0 回答 0