1. Home
  2. Computing & Technology
  3. C / C++ / C#

C# Tutorial - Getting Started

By David Bolton, About.com

3 of 8

About Example 1a

About Lesson1a

Every C# application has a certain amount of overhead in the source files. The first few lines with using refer to libraries that this application uses. If you use other libraries then you'll see more added in here here.

The namespace block is optional but good practice to keep. This puts everything in your application in the lesson1a namespace. A namespace wraps up all the types, classes, variables into one space. Without it, if you had a type called say FinancialFuture and used another type with the same name, the compiler could not distinguish them. If you are creating many classes and using other libraries, this makes it possible for you to use the same identifier names even if defined in other namespaces.

The Class definition is where the real action starts. This defines a class with one static method called Main(). This is required if you want to have something that can be run, say instead of a library. You can change the return type to int from void, but you then have to add

            return 0;
The int says that it returns a value of type int (more on ints later on this lesson) so you have to return something. That's what the return statement does. Just like in C++, the parameters to Main() are optional and can be completely removed if you want.

Console is a class that handles the Input, output and error streams.

On the next page : A bit of fun.

Explore C / C++ / C#
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. C / C++ / C#
  4. C# / C Sharp
  5. Learn C Sharp
  6. About Example 1a

©2009 About.com, a part of The New York Times Company.

All rights reserved.