Why do the values of my tuple collection not show up in watch?

两盒软妹~` 提交于 2019-12-11 17:52:18

问题


Why is it that when I run this console app:

static void Main(string[] args)
{
    var items = new List<(string login, string email)>();
    items.Add(("james", "lsdkjsdkj@skdfjd.dfkd"));
    items.Add(("james2", "lsdkjsdkj@df333.dfkd"));
    items.Add(("james", "lsdkjsdkj@skdfjd.dfkd"));
    items.Add(("james2", "lsdkjsdkj@df333.dfkd"));

    foreach (var item in items)
    {
        Console.WriteLine(item.email);
    }

    var duplicates = items.Where(e => e.login == "james");
    Console.WriteLine(duplicates.Count());

    foreach (var duplicate in duplicates)
    {
        Console.WriteLine($"Found: {duplicate.login}, {duplicate.email}");
    }

    Console.ReadLine();
}   

it correctly shows me the contents of the variable duplicates:

but when I debug, it doesn't show me the contents of duplicates:


回答1:


The Current property is just an element in the collection at the current position of the enumerator.

From MSDN:

Current is undefined under any of the following conditions:

  • The enumerator is positioned before the first element in the collection, immediately after the enumerator is created. MoveNext must be called to advance the enumerator to the first element of the collection before reading the value of Current.

  • The last call to MoveNext returned false, which indicates the end of the collection.

  • The enumerator is invalidated due to changes made in the collection, such as adding, modifying, or deleting elements.

So if you call duplicates.GetEnumerator().MoveNext(); and you will see that your Current now have data in it.

If you want see your duplicates content while debugging, use Results View.



来源:https://stackoverflow.com/questions/50700485/why-do-the-values-of-my-tuple-collection-not-show-up-in-watch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!