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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Dec 31, 2011, 6:55 AM EST
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.
Posted Dec 31, 2011, 7:18 AM EST
VulpesRank #55 · 29.2K reputationPosted Dec 31, 2011, 8:17 AM EST
Posted Dec 31, 2011, 8:55 AM EST
Sam HobbsRank #108 · 20.5K reputationPosted Dec 31, 2011, 2:24 PM EST
VulpesRank #55 · 29.2K reputationPosted Jan 1, 2012, 12:57 AM EST
Posted Jan 1, 2012, 3:00 AM EST
VulpesRank #55 · 29.2K reputationPosted Jan 1, 2012, 3:09 AM EST
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
Sam HobbsRank #108 · 20.5K reputationPosted Jan 1, 2012, 11:07 AM EST
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.
Posted Jan 1, 2012, 11:33 AM EST
VulpesRank #55 · 29.2K reputationPosted Jan 1, 2012, 12:59 PM EST
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, 1:22 PM EST
Sam HobbsRank #108 · 20.5K reputationPosted Jan 1, 2012, 1:38 PM EST
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.