Book says "A class's ToString() method is often a useful debugging aid".
Any one knows please show how it can be used to debug.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Jan 1, 2012, 6:38 PM
You can do nearly the same thing by adding an item to the watch window. Please learn about that. Note that when I first learned about these things, the internet was not available for getting help like this. The watch window is something that the MSDN is enough for learning about it and there are many articles available to help you. Just look for articles about the watch window.
Posted Jan 1, 2012, 6:22 PM
VulpesPosted Jan 1, 2012, 5:59 PM
However, for future reference, there's a bit about it here in the MSDN docs:
http://msdn.microsoft.com/en-us/library/cyzbs7s2.aspx
Posted Jan 1, 2012, 4:33 PM
Sam HobbsPosted Jan 1, 2012, 4:07 PM
Anyway, in the Debug menu is Step Into (F11) which is often called single-step since it executes one line of code each time. Also there is Step Over (F10) since it will execute a method without going into it for debugging. If you use single-step when a method is called, then the debugger will go to the first executable line in the method and then you can see what happens in the method. There is also Step Out (Shift-F11) which will finish executing a method and break at the first line afer the method call. If you are not familiar with these or if any of this is confusing, then find articles about these things.
The quickwatch window is also very useful. I use it a lot. If you do not know what the quickwatch window is then learn about that. Also learn about the watch window, which is different from the quickwatch window.
Perhaps the most important debugging technique is breakpoints; simple breakpoints can be toggled for a line using F9. It is also possible to set a breakpoint that is conditional, such as a when a variable changes in value. I have never used that for C# but it can be very useful.
At the top of the Debug menu is Windows. You should look at what is there. The Locals window is something I used a lot for C++ but it can be useful for C# too. The call stack can also be useful.
Also Debug.Print can be useful. It is like Console.WriteLine but it works for GUI programs too. It is a convenient way to show data during execution that you can look at after debugging.
Those are nearly all the debugging tools I commonly use. They are all I can think of now.
VulpesPosted Jan 1, 2012, 8:09 AM
http://www.c-sharpcorner.com/Search/?sKeywords=debugging
However, this one on Code Project which relates to VS 2010 specifically is probably as good a tutorial as you'll find:
http://www.codeproject.com/KB/cs/MasteringInDebugging.aspx
Posted Jan 1, 2012, 8:00 AM
VulpesPosted Jan 1, 2012, 5:57 AM
Sam HobbsPosted Dec 31, 2011, 7:24 PM
Posted Dec 31, 2011, 1:55 PM
VulpesPosted Dec 31, 2011, 1:17 PM
Posted Dec 31, 2011, 12:18 PM
VulpesPosted Dec 31, 2011, 11:55 AM
The ToString() method which all classes inherit from System.Object by default returns the name of the type though it can be overridden to return anything you like.
I suppose you could override it to return a combination of the values of various properties which might be useful for debugging purposes but why anyone would want to do that when we have Visual Studio's built-in debugger available I don't know.