Click here to Skip to main content
15,886,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Instead of an array or list that you use a int to get an output, you use the opisite.

E.G.

age["Bob"] = 54;
age["Lilly"] = 24;

Thanks!

What I have tried:

I couldnt find any good solutions on google.
Posted
Updated 3-May-21 15:43pm

1 solution

An array or List? No.

A Dictionary or other key/value pair collection, yes.
C#
Dictionary<string, int> collection = new Dictionary<string, int>();
collection.Add("Bob", 54);
collection.Add("Lilly", 24);
...
collection["Roberto"] = 88;
collection["Wendy"] = 65;
Dictionary<TKey,TValue> Class (System.Collections.Generic) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900