Is it possible to create a variable with a name that is a string?

Hello, I’ve searched the internet for days and I still haven’t found an answer. The problem is that I want to make many different lists (potentially hundreds), but I want to create them each with a name that fits their categories. The reason I am doing this is because I am developing a game with procedural generation, in which their will be rooms with different exits, sizes, and types.

listName = “”;
if (exitUp)
{
listName += “N”;

             }
             if (exitDown)
             {
                 listName += "S";
                 
             }
             if (exitLeft)
             {
                 listName += "E";
                 
             }
             if (exitRight)
             {
                 listName += "W";
                 
             }
             // The above is the exit denotation

             listName += sizeOfRoom.x;
             listName += ",";
             listName += sizeOfRoom.y;
             // The above adds the x value, a comma, and a y value of the room
             listName += roomType;

             // The above add the roomType text

For example, if I was looking at a room with exits up and down, a size of 8 by 4, and a type of StandardRoom, then listName would equal the string “NS8,4StandardRoom”. If I could create a List with that name, and add all rooms that fit those parameters into it, I could then search for a List with that name when I try to spawn a specific room with those qualities.

In short, if I could somehow change the text of the string into the title of a list, that would be very beneficial.

NOTE: I have looked into unity dictionaries, and I want to avoid those if possible. The problem with them is that it becomes incredibly hard to view dictionary entries, and displaying them in the inspector is a nightmare. A list, meanwhile, can be shown and modified in the inspector.

Based on [another point of reference related to this question][1], not only is this challenging to do, if it’s even possible at all through Reflection, it’s also a pretty unproductive idea regardless.

In my personal tests, a Dictionary<> only offers actual performance improvements on a pretty large scale (1000+, if not more entries) compared to simple searches through a List<>, so you probably don’t even need to worry about potential performance implications if you keep the checks simple enough.

With simple checks in mind, you could consider creating a class that tracks a List<> of Rooms, coupled with a string for a name. For changes made through script, you can then check all your groups and find one with a matching name:

// Minimal example, including base class tracking groups of rooms
// as well as the groups themselves
public class MainClass
{
	public List<RoomGroup> groups;
	
	public void AddGroup(string groupName, Room roomToAdd)
	{
		for(int i = 0; i < groups.Count; i++)
		{
			if(groups*.name == groupName)*
  •  	{*
    

_ groups*.rooms.Add(roomToAdd);_
_
return;_
_
}_
_
}_
_
// If you make it here, the group didn’t exist*_
* groups.Add(new RoomGroup(groupName, roomToAdd));*
* }*
}

public class RoomGroup
{
* public string name;*
* public List rooms;*

* public RoomGroup(string name, Room initialRoom)*
* {*
* this.name = name;*
* rooms = new List();*
* rooms.Add(initialRoom);*
* }*
}
_*[1]: c# - String as variable name - Stack Overflow