TL;DR: In C# use [DebuggerDisplay("")] on your classes and follow better practices.So lets say we have a class (C#) that looks like this:public class Person
{
public string Name { get; set; }
}What will Visual Studio’s debugger show me for this guy?
Not very awesome at all. And anything less than awesome, is just no bueno.We can make this a lot better. All the debugger is doing is calling the ‘ToString’ function on your object which by default is just returning the type name. If you see the {} around the value in the debugger you know that it is calling the ‘ToString’ method. So the first thing we could do is just override the ‘ToString’ method.
public class Person
{
public string Name { get; set; }
public override string ToString(){ return Name; }
}Which gives us:
Read more: CodeBetter
QR:
{
public string Name { get; set; }
}What will Visual Studio’s debugger show me for this guy?
public class Person
{
public string Name { get; set; }
public override string ToString(){ return Name; }
}Which gives us:
Read more: CodeBetter
QR:
0 comments:
Post a Comment