简体   繁体   中英

what is a good c# data structure with direct access?

I'm building a game in Unity and I need a good data structure that lets me access a key/property directly with optimal performance.

What I mean is for example in javascript I can do something like

var myData = {};

for (let data in somedata) {
  myData[data] = someValue;
}

console.log(myData['directToken']);

What can I use in C# that would let me do the same/similar?

You could use NameValueCollection ;

var collection = new NameValueCollection();
var someData = new List<string>(){ "directToken"};
foreach (var data in someData)
{
    collection[data] = "someValue";
}
Console.WriteLine(collection["directToken"]);

Also, you could use Dictionary with similar way instead of NameValueCollection . Only difference is NameValueCollection can contain duplicate keys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM