I’m trying to see what certain variables’ values are in a C# .NET script (it gets an XML file, extracts a bunch of nodes, builds a sorting filter of some type, applies the filter, gets the result, deletes a few things and then iterates over the results outputting them). So I can figure out what is happening where and convert the script to do the same thing in PHP.
In PHP I would just do var_dump($someData); or echo $thePath. How do you do this in .NET (C#)?
In the script there are things like:
XmlDocument someData = new XmlDocument();
string thePath = Server.MapPath( "some.xml" );
someData.Load( thePath );
and
XPathNodeIterator iterator = navigator.Select(stuff);
and so forth but I don’t always know what these things are doing (I mean, I know that there is an XML document being loaded and some portion of it is being selected to be iterated over but I want to be able to examine what various variables values are as I move through the script). I do not have access to Visual Studio… just a basic text editor and a browser.
jvenema is right – you do have access to Visual Studio, you just don’t know it (unless you don’t have the rights to install software on your machine) – the express version is free.
However, if you don’t want to wait for that, and you don’t mind modifying your page to show variable values, you can put this in anywhere for guerilla debugging (since it sounds like you’re using ASP.NET):
Depending on where in your code you do this, it probably won’t land inside your viewable HTML, and it might even produce broken HTML output. However, if you view the page source in your browser, you’ll be able to view it.
A better approach might be to declare a page-level string variable to which you can append your debug data:
Then, in your aspx page template, just pick a good spot, perhaps at the bottom of the page, but within the viewable HTML and output it using the <%= %> syntax (which is a shortcut :