Visual C# 2005 Recipes



A P P L I C AT I O N D E V E L O P M E N T
3
csc @commands.rsp
To achieve the equivalent of the previous example, commands.rsp would contain this:
/target:exe /main:HelloWorld /out:MyFirstApp.exe HelloWorld.cs ConsoleUtils.cs
The Code
The following code lists a class named ConsoleUtils that is defined in a file named ConsoleUtils.cs:
using System;
namespace Apress.VisualCSharpRecipes.Chapter01
{

public class ConsoleUtils
{

// A method to display a prompt and read a response from the console.
public static string ReadString(string msg)
{

Console.Write(msg);
return Console.ReadLine();

}
// A method to display a message to the console.
public static void WriteString(string msg)
{

Console.WriteLine(msg);
}
// Main method used for testing ConsoleUtility methods.
public static void Main()
{

// Prompt the reader to enter a name.
string name = ReadString("Please enter your name : ");

// Welcome the reader to Visual C# 2005 Recipes.
WriteString("Welcome to Visual C# 2005 Recipes, " + name);

}
}
}
The HelloWorld class listed next uses the ConsoleUtils class to display the message "Hello,
world" to the console (HelloWorld is contained in the HelloWorld.cs file):
using System;
namespace Apress.VisualCSharpRecipes.Chapter01
{

class HelloWorld
{

public static void Main()
{

ConsoleUtils.WriteString("Hello, world");
Console.WriteLine("\nMain method complete. Press Enter.");
Console.ReadLine();

}
}
}