C#
  Home arrow C# arrow Page 5 - 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  
Moblin 
JMSL Numerical Library 
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 / 257
    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


    C# - An Introduction - C# Building-Blocks


    (Page 5 of 9 )

    Whenever you write a C# statement, it will be part of a block, skillfully called a “Block of code”.  It’s much the same as paragraphs in English, which consist of a number of statements.

    It is called a block because it’s consists of related C# statements that will do the job that it’s created for. C# blocks may contain zero, one or many statements.  These blocks must be delimited with curly braces “{ }” like the following example:

    {
        int memory = 2 + 5;
        Console.WriteLine(memory);
        Console.WriteLine("so it's 7, right?");
    }

    This is a block of code that contains three statements.  There are a number of important points that you must understand here:

    1. int is a keyword and VS.Net will color it blue so that you can differentiate it
    2. There is a semicolon at the end of each of the three statements
    3. Each line contains only one statement

    You can have two statements on the same line, simply because the C# compiler knows that you end the statement with the “;”.   So you can write the last building block like so:

    {
        int memory = 2 + 5;Console.WriteLine(memory);Console.WriteLine("so it's 7, right?");
    }

    It’s only apparent that by convention you should write one statement on a line so that your code is readable. You can also nest blocks, meaning you can write one block inside another.  Look at the following block:

    {
        int memory = 2 + 5;
        if(memory == 7)
        {
            Console.WriteLine("hi, I'm Michael");
        }
    }

    Again don’t look at the code itself; look only at the blocks.  Here we have two nested blocks of code.   For now, know that we can create blocks inside other blocks.  Later, we will discuss how they can be useful.

    Something important to note: When you type the left curly brace “{“, and write your code, then closing it with the right curly brace “}”, you will notice that VS.Net momentarily bolds the entire block.  It is nothing more than VS.Net’s way of showing you the contents of that block.

    There are three more sections that will discuss code organization.

    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#







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