Home arrow C# arrow Page 5 - C# - An Introduction
C#

C# - An Introduction


Learn the fundamentals of C# as Michael takes us on an introductory tour, including keywords, identifiers, and much more.

Author Info:
By: Michael Youssef
Rating: 4 stars4 stars4 stars4 stars4 stars / 310
November 17, 2003
TABLE OF CONTENTS:
  1. · C# - An Introduction
  2. · Keywords
  3. · Identifiers
  4. · C# Statements
  5. · C# Building-Blocks
  6. · Commenting Your Code
  7. · Case-Sensitivity and Syntax Errors
  8. · Organizing Code Using White Space
  9. · Conclusion

print this article
SEARCH DEVARTICLES

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.


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