Home arrow C# arrow Page 4 - The Basics of C#: A "HelloWorld" Application
C#

The Basics of C#: A "HelloWorld" Application


C# is part of Microsoft's evolutionary .NET environment. It has collected the best features and aspects of many other programming languages including Visual Basic and C++. In this article James will show us how to create and compile a simple "HelloWorld" C# console application.

Author Info:
By: James Yang
Rating: 4 stars4 stars4 stars4 stars4 stars / 41
January 09, 2002
TABLE OF CONTENTS:
  1. · The Basics of C#: A "HelloWorld" Application
  2. · Hello World Example
  3. · HelloWorld source code explained
  4. · Simple C# language features
  5. · Conclusion

print this article
SEARCH DEVARTICLES

The Basics of C#: A "HelloWorld" Application - Simple C# language features
(Page 4 of 5 )

The first and most confusing point for any Visual Basic developer to remember is that C# is case sensitive. If you typed "console" instead of "Console" for example, then the compiler would spit out an error message, like this:

Case sensitive compilation error

It's not only commands or function names that are case sensitive. Variables are also case sensitive, meaning that the variable "a" is different to the variable "A". Because of this case sensitivity, certain naming guidelines have been developed to aid developers when naming functions, variables, etc, and Microsoft recommends that you adhere to these guidelines.

Firstly, variables should be named to help with intrinsic documentation. For example, if I wanted to create a variable to deal with how many apples I have, then I would call that variable "numApples" and not something like "a". Secondly, variables whose names consist of more than one word (such as "databaseName") should use the camelCase naming convention. The camelCase naming convention dictates that when naming multiple-word variables, every letter should be lower case, accept for the first letter of each new word after the first, which should be capitalized. Some camelCase examples include "myName", "yourStreetNum", and "timeLeftToGo".

Secondly, in C# source code, white spaces are ignored. C++ and Java developers have enjoyed this for years. All commands are terminated with a semi-colon (";") instead. This gives us great freedom when formatting and stylising our source code, letting us make it as readable as possible.

Thirdly, C# is a block structured language, meaning that all statements are part of a block of code. Each block of code is opened and closed by using curly braces: "{" and "}" respectively.

Lastly, C# supports three different types of comments. These will appear common to current C++ developers. For one line comments, you use the "//" syntax, like this:

// This is a comment

One line comments cannot span multiple lines, so the comment shown below would cause the C# compiler to flag an error:

// This is the first line of the comment

and this is the second ERROR line


If you need to add a comment to your source code which spans more than one line, you can use the "/* ... */" syntax, like this:

/*

This is a multi-lined comment

and will not raise an error at all

*/


The last type of comment that C# supports is the triple-slashed comment. This is a special type of comment that allows us to internally document our code. It is a single line comment that can be used by the .NET compiler to create useful documentation for your application. It is used like this:

/// Important comment
blog comments powered by Disqus
C# ARTICLES

- Introduction to Objects and Classes in C#, P...
- Visual C#.NET, Part 1: Introduction to Progr...
- C# - An Introduction
- Hotmail Exposed: Access Hotmail using C#
- Razor Sharp C#
- Introduction to Objects and Classes in C#
- Making Your Code CLS Compliant
- Programming with MySQL and .NET Technologies
- Socket Programming in C# - Part II
- Socket Programming in C# - Part I
- Creational Patterns in C#
- Type Conversions
- Creating Custom Delegates and Events in C#
- Inheritance and Polymorphism
- Understanding Properties in C#

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials