Replies: 2 comments 3 replies
-
To clarify, what would you expect the following to print? public static void Main()
{
var sb = new Dictionary<int, int>()
{
{1,1},
{2,1},
};
foreach (var kv in sb)
{
kv.Value += 1;
Console.WriteLine("Editing " + kv.Key + ": " + sb[kv.Key]);
}
} KeyValuePair<int,int> is just a simple struct containing two ints (which are copied by value), so any mutations to it wouldn't affect the underlying Dictionary even if it wasn't readonly. |
Beta Was this translation helpful? Give feedback.
1 reply
-
On which version of .NET Framework and compiler it can compile? I don't think the rule on struct-returning property has changed. Maybe related to C# 5 foreach change? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In previous versions of .net framework, the following code will throw an Exception:
and now it won't even compile with the latest version of .net core. The error as can see here is: "Property or indexer 'System.Collections.Generic.KeyValuePair<int,int>.Value' cannot be assigned to -- it is read only"
What is the purpose behind avoiding iterators' value edition?
Beta Was this translation helpful? Give feedback.
All reactions