Click here to Skip to main content
15,884,353 members
Articles / All Topics

Function Evaluation within Immediate Windows with No Side Effect

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
30 Jul 2017CPOL1 min read 3.7K  
Function evaluation within immediate Windows with no side effect

I make quite heavy use of Immediate Window. It's a nice tool within Visual Studio to print variable values, evaluate expressions and even execute statements. However, there are times when doing this type of activity changes the state of particular object.

Let me describe the scenario with an example. Let’s say I have an Employee class as follows:

This class is consumed as shown below:

Once the break-point is hit, Salary property of this object can be inspected within Visual Studio.

If I need to run a function of this object, I can easily do it from Immediate Window. In this case, if I call GiveEmployeeARaise method of the Employee object, that function changes the value of Salary which is reflected in Watch window here.

There could be times when I don’t want these test runs of certain function change the state of this object. This is where you can call the method with nse (No Side Effect) switch. Let’s call the same method again but using the switch.

So this time, the Salary property didn’t get incremented.  Isn’t this cool? When I am sure that there is no problem with that state change, you can just remove the nse switch.

Until next, happy debugging.

Filed under: CodeProject, Debugging

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Canada Canada
Kamran Bilgrami is a seasoned software developer with background in designing mission critical applications for carrier grade telecom networks. More recently he is involved in design & development of real-time biometric based security solutions. His areas of interest include .NET, software security, mathematical modeling and patterns.

He blogs regularly at http://WindowsDebugging.Wordpress.com

Comments and Discussions

 
-- There are no messages in this forum --