问题
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