Preventing lambda from being included in the hosting process is DebuggerHidden

private static void Main() { Console.WriteLine(GetRandomInteger()); Console.ReadLine(); } [DebuggerHidden] private static int GetRandomInteger() { Func<int> random = () => 4; return GetRandomInteger(random); } [DebuggerHidden] private static int GetRandomInteger(Func<int> random) { return random(); } 

Using the code above, is there a way to prevent a line Func<int> random = () => 4; during debugging?

+4
source share
2 answers

Well, you can use a private function with the [DebuggerHidden] attribute instead of labmda and assign Func<int> to the delegate for the private function.

+4
source

[DebuggerHidden] can be used for a property, and this property appears to behave as you would like:

 [DebuggerHidden] private static Func<int> random { get { return () => 4; } } 

This is a workaround, as is another answer; however, it retains the lambda and may be closer to the original intention.

+2
source

Source: https://habr.com/ru/post/1481811/


All Articles