A quick and dirty way to debug JavaScript web apps is to pass values to the alert() function. Not only is it short to type, but the interpreter automatically type-casts as string anything you pass as argument. In C# and VB, you can use the MessageBox.Show() method, but it is verbose, and you have to explicitly call ToString() on the argument(s) to avoid errors. This tutorial shows you how to get the same simplicity in your Visual Studio projects!public void alert( object s ) {
MessageBox.Show( s.ToString() ); // Explicit conversion here
} Note: compiled, strongly-typed language like C# and VB beat runtime speed of loosely-typed and/or interpreted languages like JavaScript. Use constructs like Object (or var) sparingly!
MessageBox.Show( string1 , string2 , myNumber.ToString() ); // Perfectly valid! But let's revise our code to accept an array instead to get more control over output formatting.
Here's a revised method that takes an array of strings as parameter. You could cycle through array elements to show one "alert" at a time (tedious), or use the Join() method to display individual array elements in a recognizable pattern.public void alert( params string[] args ) {
MessageBox.Show( "|" + args.Join("|\n|") + "|" );
}