Professional Documents
Culture Documents
Overview of C#
Overview of C#
Structure of a C# Program
Hello, World The Class The Main Method The using Directive and the System Namespace
Hello, World
using System;
class Hello { public static void Main() { Console.WriteLine("Hello, World"); } }
The Class
A C# application is a collection of classes, structures, and types A class Is a set of data and methods
A C# application can consist of many files A class cannot span multiple files
Use an uppercase M, as in Main Designate one Main as the entry point to the program Declare Main as public static void Main
System is the most commonly used namespace Refer to classes by their namespace The using directive
System.Console.WriteLine("Hello, World");
The Console Class Write and WriteLine Methods Read and ReadLine Methods
Provides access to the standard input, standard output, and standard error streams Only meaningful for console applications
Both methods are overloaded A format string and parameters can be used
Read reads the next character ReadLine reads the entire input line
Commenting Applications
A well-commented application permits a developer to fully understand the structure of the application
Single-line comments
// Get the users name Console.WriteLine("What is your name? "); name = Console.ReadLine( );
Multiple-line comments
Type the name of the application Click Start Without Debugging on the Debug menu