Suppose there are two arrays. One array is used to store names and the other array to store marks. How can I display a name with its corresponding mark? Both arrays are of different types.
1 Answer
Try to use something like:
int[] marks = { 1, 2 };
string[] names = { "one", "two"};
var dictionary = names.Zip(marks, (s, i) => new { s, i })
.ToDictionary(item => item.s, item => item.i);
or
var dictionary = new Dictionary<string, int>();
for (int index = 0; index < marks.Length; index++)
{
dictionary.Add(names[index], marks[index]);
}
and then
foreach (var item in dictionary )
{
Console.WriteLine("{0}, {1}",
item.Key,
item.Value);
}
CustomObject. Or key-value pairs like a dictionary. OrTuple<name,mark>