I'm interested in how to get value from C# lookup structure.
Example:
var myLookup = (Lookup<string, int>)data.Rows.Cast<DataRow>().ToLookup(row => row["Name"], row => row["Id"]);
foreach (var myLookupItem in myLookup)
{
Debug.WriteLine("Name: " + myLookupItem.Key);
Debug.WriteLine("Id: " + myLookupItem.ToString());
}
Problem is that the
myLookupItem.ToString()
doesn't display actual value, instead only System.Linq.Lookup2[System.String,System.Int32]
is displayed.
Later on, I should get the lookup value using lambda:
int lookupValue = myLookup.Where(x => x.Key == "Test").Select(x => x).FirstOrDefault());
but this also gives the same as above.
Please advise how to achieve this.
Thanks in advance.
In this program, no arguments are passed to the function “sum”. But, values are returned from this function to main function. Values of the variable a and b are summed up in the function “sum” and the sum of these value is returned to the main function.
In C or C++, we cannot return multiple values from a function directly.
%d takes integer value as signed decimal integer i.e. it takes negative values along with positive values but values should be in decimal otherwise it will print garbage value. ( Note: if input is in octal format like:012 then %d will ignore 0 and take input as 12) Consider a following example.
%d is a format specifier, used in C Language. Now a format specifier is indicated by a % (percentage symbol) before the letter describing it. In simple words, a format specifier tells us the type of data to store and print. Now, %d represents the signed decimal integer.
That's because the lookup item is a collection. You can see every value of the lookup like this:
foreach (var myLookupItem in myLookup)
{
Debug.WriteLine("Key: " + myLookupItem.Key);
foreach (var myLookupValue in myLookupItem)
{
Debug.WriteLine("Value: " + myLookupValue);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With