C#
  Home arrow C# arrow Page 7 - 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    C# - An Introduction - Case-Sensitivity and Syntax Errors


    (Page 7 of 9 )

    As I’ve mentioned before, C# is a case-sensitive programming language.  What does this mean?  In C#, if you named an item “Michael” (with a capital “M”) then it’s not the same as “michael”.  The C# compiler will not understand that Michael = Michael, and it will consider them as two different items.  Take care when giving names in your code.

    The following is a program that outputs a line to the console.

    using System;
    namespace ConsoleApplication2
    {
        /// <summary>
        /// Summary description for Class1.
        /// </summary>
        class Class1
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main(string[] args)
            {
                Console.WriteLine("Hello, I'm Michael");
            }
        }
    }

    You most likely know a little bit more about this code.  You know that the blue words are keywords and the green lines are comments but let’s talk about case-sensitivity.

    All the keywords are made up of small letters.  If you were to try and delete it and type it in with an uppercase letter, the color would not be blue.  When you compile your program you will receive an error.

    Later on you will learn what things can be written in uppercase characters, and what things must be written in lowercase characters -- by now, you know that keywords must be written in lowercase.

    Earlier, I said that if you type “michael”, instead of “Michael” (the item named with a capital “M”), the compiler will generate an error. This type of error is known as a syntax error.

    In the English language, if you typed “noote” instead of “note”, it’s a spelling error.  You can associate a syntax error as a a spelling error in English.  With C#, the compiler will generate an error telling you about it (the error message will depend on the situation).

    A syntax error is not only related to case-sensitive issues.  As you’ll see, the next example will also produce a syntax error:

    {
    Console.WriteLine(“Hello”);


    We said before that C# blocks must delimited by “{“ and “}”.  In this example we didn’t close the block, so it is considered a syntax error.

    To avoid the “opening and closing” problem you can do the following:

    1. If you want to create a block of code, type the opening and closing curly braces on the same line:

      { }

    2. Then press the enter key two times, and you will have something like the following:

      {

      }

    3. Now you can write your code without worrying about the opening and closing curly braces.

    Another example of a syntax error:

    {
        Console.WriteLine(“Hello”)
    }

    In this example, I didn’t forget to close the block.  I did, however, forget to put a semicolon at the end of the statement.  This is also considered a syntax error.  VS.Net will place a jagged line under the place of the syntax error.  Be careful, as sometimes, I find that the error can be related to the next line of code.

    There are many other things that can cause syntax errors.  Don’t worry, as we will learn more about them.  Before you learn more about C#, you should understand syntax errors for a couple of reasons.  The first reason is that the most common syntax error is related to case-sensitive issues.  The second reason is that I want you to minimize your syntax errors and focus on learning the language.

    You must know that your code will not compile and execute until you fix all of the syntax errors in your code.  VS.Net will help you track your syntax errors by providing an error message describing the error along with placing the jagged line under the line where the syntax error has occurred. Syntax errors are also known as compile-time errors or compilation errors.

    Next, we will learn how we can organize our code, as VS.Net does, to improve readability.

    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 3 hosted by Hostway