I'd like to use the following C#6 code
var joe = new Self();
Console.WriteLine(joe);
... and get the following output:
joe
The following attempt
class Self {
public string Name { get; set; } = nameof(this);
public override string ToString() {
return Name;
}
}
fails as nameof
cannot be applied to this
. Is it there a workaround for this problem?
EDIT. The scenario I'm working with assures that no two references point to the same Self
object.