Debugging an IEnumerable method

前端 未结 2 1042
忘了有多久
忘了有多久 2021-02-06 23:40

I have a method with returns an IEnumerable and I\'m trying to debug the code inside that method.

Each time I step through the code in Visual Studi

2条回答
  •  生来不讨喜
    2021-02-07 00:22

    It should be no problem to debug IEnumerable implementation... May be you just using wrong .dll (if you enumerator is in external library)...

    You may try a simple test console, and go from here

    class Program
    {
        static void Main(string[] args)
        {
            foreach (String foo in new Foo())
            {
                Console.WriteLine(foo);
            }
        }
    }
    
    class Foo : IEnumerable
    {
        #region IEnumerable Members
    
        public IEnumerator GetEnumerator()
        {
            yield return "fake # 1";
            yield return "fake # 2";
        }
    
        #endregion
    
        #region IEnumerable Members
    
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    
        #endregion
    }
    

提交回复
热议问题