So, this works:
class:
public class c_entry
{
public string Name { get; private set; }
public c_entry(string name)
{
Name = name;
}
}
Create instance and send variable name as a parameter
public void method()
{
c_entry c = new c_entry(nameof(c));
}
But what I really want to be able to do is set the Name
by just referring to its instance name
from inside the class so I don't have to pass the nameof(instance)
as a parameter
public class c_entry
{
public string Name { get; private set; }
public c_entry()
{
Name = nameof(this); // This line won't compile because "this" expression doesn't have a name
}
}
I don't think this is possible - but is it?