c# - Visual Studio 2012 不允许我调试接口(interface)的实现

标签 c# visual-studio visual-studio-debugging

我正在查看 LINQ 中的一些查询并想了解其实现,因此我想到了调试相同的内容,但是当我尝试这样做时,Visual Studio 没有进入接口(interface)的实现,不知道为什么是吗。我正在使用 Visual Studio Community 2015。这是我的代码

class Client
    {
        static void Main(string[] args)
        {
            string[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry" };
            var result = words.OrderBy(a => a, new CaseInsensitiveComparer());
            Console.Read();
        }
    }
    public class CaseInsensitiveComparer : IComparer<string>
    {
        public int Compare(string x, string y)
        {
            Console.WriteLine("x is " + x + " & y is " + y+" the value is "+ string.Compare(x, y, StringComparison.OrdinalIgnoreCase));
            return string.Compare(x, y, StringComparison.OrdinalIgnoreCase);
        }
    }

最悲伤的部分是我也无法在控制台窗口中打印任何内容

Console.WriteLine("x is " + x + " & y is " + y+" the value is "+ string.Compare(x, y, StringComparison.OrdinalIgnoreCase));

我知道有很多与此相关的重复问题,但我尝试了所有方法,但没有一个对我有用。

  1. 我尝试清洁溶液
  2. 删除 Obj 和 Bin 文件夹
  3. 关闭解决方案并再次打开并重建它 对我来说没有任何作用。

更新1

我已将调试器放置在 IComparer 的实现中 enter image description here

最佳答案

您的 .OrderBy() 调用仅在您使用其结果时才会被评估(就像许多 linq 方法的情况一样)。由于您没有使用结果,因此代码实际上并未运行。

在末尾添加一个.ToList(),它将运行:

var result = words.OrderBy(a => a, new CaseInsensitiveComparer()).ToList();

您可能无法单步执行 .OrderBy() 调用,但您可以在比较器实现中放置断点。

关于c# - Visual Studio 2012 不允许我调试接口(interface)的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40516057/

相关文章:

c# - 循环泛型类型参数

c# - string.Format 与 string.Join

visual-studio - WiX:旧版本不会在“添加/删除程序”列表中消失

c# - Visual Studio 2015 观察评估超时

c++ - 是否可以调试使用自定义加载程序加载的 dll?

c++ - 如何使用 visual studio 2015 正确调试 MFC 容器

c# - 作为第一个参数委托(delegate)给扩展方法

c# - 纯数字文本框

visual-studio - Visual Studio 网站引用路径

visual-studio - 在Visual Studio 2019中添加Web引用发生了什么?