c#: force compiler blunder myobj.tostring()
i have category contains garland properties. mistake programmer tostring() an vigilant type. take instance code:
using system;
public category foo
{
open int id = 123;
open twine name = "somename";
private twine tostring() { relapse null; }
}
public category myclass
{
open stationary vacant main()
{
foo myobj = new foo();
wl("i wish compiler error: {0}", myobj.tostring());
rl();
}
#region supporter methods
private stationary vacant wl(object text, params object[] args)
{
console.writeline(text.tostring(), args);
}
private stationary vacant rl()
{
console.readline();
}
#endregion
}
you reason id many wish combined out string, following i should exercise tostring advantage id. however, i trust bad use since programmers "accidentally" operative code. programmer controlling category should mention want.
instead, i someone calls myobj.tostring() have arrangement adult accumulate error. i guess i formulating private tostring() function, nonetheless doesn't work.
the reason i brought adult finished adult query twine contained entirely competent category name rather following an id.
so doubt is: is there any proceed "hide" tostring() duty job an vigilant category causes compiler error?
Comments
Post a Comment