Using DebuggerStepThrough Attribute
While working on a complex code, we often come across situations where we need to debug a lot of code to find/fix the issue(s). That also includes going through lots of methods (probably related or unrelated). The .NET Framework provides a way to avoid unwanted "Step in" through the methods. Using DebuggerStepThrough (using System.Diagnostics) attribute, you can skip debugging of unwanted methods and reduce the debugging time to some extent.
For example, I have the below class file that contains two classes ( a class in which there is a method to reverse a string and a class that logs reversed string to output window). This attribute is applicable to Class, Struct, & Method.
While working on a complex code, we often come across situations where we need to debug a lot of code to find/fix the issue(s). That also includes going through lots of methods (probably related or unrelated). The .NET Framework provides a way to avoid unwanted "Step in" through the methods. Using DebuggerStepThrough (using System.Diagnostics) attribute, you can skip debugging of unwanted methods and reduce the debugging time to some extent.
For example, I have the below class file that contains two classes ( a class in which there is a method to reverse a string and a class that logs reversed string to output window). This attribute is applicable to Class, Struct, & Method.
If DebuggerStepThrough attribute is applied to the method, any breakpoints inside that method won't be hit while debugging the application. If DebuggerStepThrough attribute is applied to a class, any breakpoints inside the class will not be hit.
- class Program
- {
- static void Main(string[] args)
- {
- //Console.WriteLine("test");
- string name = "TestString";
- name = ReverseString(name);
- Console.WriteLine(name);
- Logger.LogMessages(name);
- }
- private static string ReverseString(string name)
- {
- Debug.WriteLine(name);
- Debug.WriteLine(name.Length);
- char[] strArray = name.ToCharArray();
- Array.Reverse(strArray);
- return new string(strArray);
- }
- }
For this class, I know that LogMessage is no more than showing/redirecting the data variable to console/output window. So, decorating this method would skip the step in process.



Join the conversation! Your thoughts help the community grow.