spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column116


JScript .NET, Part X: Displaying Information

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


Using System.Console

The class System.Console is slightly more powerful than the print statement. Its methods feature display options that are not supported by the print statement. The WriteLine() method mimics the print statement. The Write() method displays a string without appending a newline character. The ReadLine() method reads from the command line, starting from the end of the previous output string, and ending at the end of the line. Having both read and write functionalities enables you to create a dialog with the user.

To use classes from the .NET framework, such as the System.Console above, you need to import the namespace to which the class belongs. Then, when you call a method, you don't need to specify the fully qualified name of the method. Notice again, that the System.Console class is supported only when you compile your JScript .NET code with the jsc compiler and run it from the command line. Using the System.Console class in an ASP.NET page or in Code Behind JScript .NET code will yield a compilation error.

The following JScript .NET script is similar to the one on Page 2; we just replaced the print statements with calls to System.Console.WriteLine() (col116ex1.js):

import System;
class HelloWorld{
  //constructor
  function HelloWorld() {
    Console.WriteLine("Object Constructed");
  }
  
  function TypeHello() {
    Console.WriteLine("Hello World.");
  }
  
}

var myHelloWorldObj = new HelloWorld();
myHelloWorldObj.TypeHello();

The following example shows a dialog with the user. It asks for his or her name, and echoes it back:

import System;
System.Console.Write("What is your name: ");
var name : String = Console.ReadLine();
Console.Write("Hello ");
Console.Write(name);
Console.WriteLine("!");

Notice the usage of both Write() and WriteLine(). Whenever we want to go to the next line, we use the WriteLine() instead of Write(). The following command-line window shows the code listing of the above dialog, col116ex3.js, its compilation, and its execution.


Next: How to use System.Windows.Forms.MessageBox

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: August 12, 2002
Revised: August 12, 2002

URL: http://www.webreference.com/js/column116/3.html