Consider this C# example:
public sealed class TestClass { private Dictionary<string,int> myDictionary = []; public int TestMethod() => myDictionary["foo"] = 3;}
Internally, when TestMethod()
is called, will there be two dictionary lookups (one for setting the foo
key and one for returning that key's value from the dictionary)? Or is the compiler smart enough to only do a single lookup for setting the foo
key, and simply return the value 3
?
I'm just wondering if I can shorten this:
public sealed class TestClass { private Dictionary<string,int> myDictionary = []; public int TestMethod() { var val = 3; myDictionary["foo"] = val; return val; }}