C#
  Home arrow C# arrow Page 6 - C# - An Introduction
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  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
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#

C# - An Introduction
By: Michael Youssef
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 251
    2003-11-17

    Table of Contents:
  • C# - An Introduction
  • Keywords
  • Identifiers
  • C# Statements
  • C# Building-Blocks
  • Commenting Your Code
  • Case-Sensitivity and Syntax Errors
  • Organizing Code Using White Space
  • 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

    Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!

    C# - An Introduction - Commenting Your Code


    (Page 6 of 9 )

    Just like any other language, when writing C# code you can also add comments. A comment is simply a section of text that you write to explain or describe your code.  For example, you have some block of code that adds two numbers, so you use comments to describe the operation of this block of code like the following:

    {
        // This block of code will add 2 numbers and then put
       // the result in the memory
        int memory = 2 + 5;
    }

    Another feature of VS.Net is coloring the comments green.  You can write your comments using any language (English, French, etc); the C# compiler will simply ignore them.  You can think of comments as something that can live with your C# code.  In more complex blocks of code you will find that comments are very useful, especially if you are reading other programmers’ code.   Their comments will help you understand many things.

    There are two ways to write comments in C#. The first way is using multi-line comments; the second, using single-line comments.

    Multi-line comments begin with the characters “/*” and end with the characters “*/” as follows:

    /* this block of code will add 2 numbers
    * and then put the result in the memory */

    There are a few things that we must discuss here. This is a multi-line comment so you can press the Enter key after the opening characters “/*” and each time you press the enter key (for a new line) you will get a “*” character at the beginning of each new line.  The job of this character is to tell you that you have a new line in your comments.  You can delete this character and continue writing your comments.  When finished, you must close it with “*/” characters.  When you close your multi-line comments, VS.Net will bold all the text contained in your comments so that you may see the entire block of comments you have just written.

    In multi-line comments you can write anything except the closing character “*/” , asVS.Net will think that you want to close the comments.

    So you can’t write the following:

    /* the only special character that you can't write
    * Inside the multi-line comments is the "*/" character */

    Here, we wrote the closing characters as part of our multi-line comment.   Note that after the closing characters in the second line “*/” the text color is black, meaning it is no longer recognized as a comment.

    A single-line comment begins with the characters “//”.  You can write your comments only on this single line as follows:
     
    // This block of code will add 2 numbers and then put
    int memory = 2 + 5;

    If you want to write more than one line in your comment then you must begin each line with “//” characters as follows:
     
    // This block of code will add 2 numbers and then put
    // the result in the memory
    int memory = 2 + 5;

    You can write the single-line comment in the same line with your statement like so:

    int memory = 2 + 5; // this is a statement

    There is a third way to comment your code; however, I prefer to not discuss it now.  Rather, I will show you what the third method looks like: 

    /// <summary>
    /// The main entry point for the application.
    /// </summary>

    You will find this kind of commenting in C# projects created by VS.Net and it helps you to document your application.

    Documentation is a help system developers create so that the application’s users can learn how to make use of the application.  Later on, I will give you an overview of how to create documentation for your application using this commenting system.

    Some developers have said that this is not a comment because you don’t comment your code; rather you describe it.  Nevertheless, we will discuss it later.

    More C# Articles
    More By Michael Youssef


     

    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#


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway