Im trying to clean up my code and at the same time avoid reducing performance. I have the following for-each loop id like to clean up:
Dictionary<string, string> algorithmsDictionary = GetAlgorithmsDictionary();
foreach (KeyValuePair<string, string> item in algorithmsDictionary)
{
string hashValue = _hash.CalculateHash(data, item.Value);
CreateTextBox(item.Key).Text = hashValue;
}
My thoughts are to remove algorithmsDictionary assignment and just use GetAlgorithmsDictionary() inside the foreach signature:
foreach (KeyValuePair<string, string> item in GetAlgorithmsDictionary())
{
string hashValue = _hash.CalculateHash(data, item.Value);
CreateTextBox(item.Key).Text = hashValue;
}
As you can see the latter looks more clean without the algorithmsDictionary assignment but is there a performance cost or bad practice using a method call inside a for-each signature?