using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class example : MonoBehaviour
{
    public TheClass theClassObj;
    public static Dictionary<string, TheClass> dictionary = new Dictionary<string, TheClass>();
    public class TheClass
    {
        public string valueToDetect;
        public TheClass(string _value)
        {
            valueToDetect = _value;
            dictionary.Add(valueToDetect, this);
        }
    }
    
    public static TheClass TheObject1 = new TheClass("123");
    public static TheClass TheObject2 = new TheClass("321");
    void Start()
    {
        foreach (var item in dictionary)
        {
            if (item.Key=="123")
            {
                theClassObj = item.Value;
                print(theClassObj.valueToDetect); //returns "123" so it works
            }
        }
    }
}