"without using any dummy classes" eh? OK...
Look at the standard ToString method:
It is implemented by the
object
class (from which all the other classes are derived) and it returns a string which is the full name of the object.
Most (but not all) derived classes override this to provide a string that is more relevant to the actual instance content:
int
overrides it to return a string representation of the integer value,
bool
overrides it to return either "true" or "false", and so on. If you create your own class, you can also override it:
public class MyClass
{
public string Name { get; set; }
public DateTime InsertDate { get; set; }
public override string ToString()
{
return Name + " " + InsertDate.ToShortDateString();
}
}
When you call ToString on an instance, the system works out the highest level override and calls that instead of the default
object
implementation.