I'm curious if there's a way to tell a class being constructed to reference an existing instance.
For example:
class MyClass
{
string _name;
static List<MyClass> _existing = new List<MyClass>();
MyClass(string name)
{
foreach(MyClass existing in _existing)
{
if (existing._name == name)
{
// Set this instance to "existing"
return;
}
}
_name = name;
_existing.Add(this);
}
}