I'm just messing around with some data types of C# in order to understand them. I've been trying for a while to understand why this dictionary is turned into a KeyValuePair. Here's my code:
class Program
{
static Dictionary<string, int> operatii(int a, int b)
{
Dictionary<string, int> calculare = new Dictionary<string, int>();
calculare.Add("suma", a + b);
calculare.Add("produs", a * b);
return calculare;
}
static void Main(string[] args)
{
foreach(Dictionary<string, int> dict in operatii(5, 6))
{
Console.WriteLine();
}
}
}
And I'm getting this error:
Error CS0030 Cannot convert type 'System.Collections.Generic.KeyValuePair<string, int>' to 'System.Collections.Generic.Dictionary<string, int>'
Now as I'm writing this I've understood that my logic was flawed, and the first parameter of the foreach cannot be a Dictionary.
But how does C# know that this should've been a KeyValuePair? Maybe I really meant to write Dictionary in there, and make the foreach run only once (because I only have one Dictionary).
Thanks.