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


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