C#
  Home arrow C# arrow Page 4 - The Basics of C#: A "HelloWorld"...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C#

The Basics of C#: A "HelloWorld" Application
By: James Yang
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2002-01-09

    Table of Contents:
  • The Basics of C#: A "HelloWorld" Application
  • Hello World Example
  • HelloWorld source code explained
  • Simple C# language features
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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

    More C# Articles
    More By James Yang


     

    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#






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT