bool[string] = true; array possible?

My question is simple, is it possible to put a string variable in the array brackets versus the int requirement?

I am still fairly new to C# but everything that I’ve tried so far has failed. My goal is to be able to check if a character is unlocked, so:

if (unlocked[name] = true)
//execute unlocked code at select screen

I am dreading having to assign an int number to every character & making 20 different scripts. Thanks all for your help.

P.S. alternatively, if there is a way that I could check if any string in the array = name then I could make that work too. So something like:

if (unlocked[1-20] = name)
//execute unlocked code

I was on mobile so i wrote as little as possible.

With arrays you are stuck with integer indexing, but there are other types of lists & Dictionaries that make it possible to index stuff with other datatypes, like stings or even GameObjects etc.

Here’s an example using a Dictionary.

using System.Collections.Generic;


Dictionary<string, bool> unlocked = new Dictionary<string, bool>();
unlocked.Add("something", false);

//this will throw an error if u didn't add anything with key "something"
bool isUnlocked = unlocked["something"];

//this is safer. Enters the if only if key "something" exists.
// and changes the value of isUnlocked to the found value
bool isUnlocked = false;
if (unlocked.TryGet("something", out isUnlocked))
   if (isUnlocked)//do something...

Negative. Array’s all have to be accessed via an index.

To the second question however, you could loop through the entire array to accomplish that.