Home > Microsoft .Net Development Tips > C# Development > Identifiers and keywords in C#
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

C# DEVELOPMENT

Identifiers and keywords in C#


Joseph Mayo
10.18.2002
Rating: -2.67- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Like other structured and non-structured languages, C# uses a number of identifiers and keywords that you must know if you want to program without having to have a manual at your elbow. This tip, excerpted from InformIT, discusses these vital parts of the language.

The InformIT article is excerpted from C# Unleashed. Click here to learn more about the book or to buy it.


Identifiers are names of various program elements in the code that uniquely identify an element. They are the names of things like variables or fields. They're specified by the programmer and should have names that indicate their purpose.

Keywords are reserved words in the C# language. Because they're reserved, they can't be used as identifiers. Examples of keywords are class, public, or void—they are the names of permanent language elements.

Identifiers

Identifiers are names used to identify code elements. The class name HowdyPartner on Line 7 of Listing 1 is an example of an identifier. Identifiers should be meaningful for their intended purpose. For example, the HowdyPartner program prints the words "Howdy, Partner!" to the console.

The C# character set conforms to Unicode 3.0, Technical Report 15, Annex 7. Unicode is a 16-bit character format designed to represent the many characters sets from all languages worldwide. Any Unicode character can be specified with a Unicode escape sequence, u or U, followed by four hex digits. For example, the Unicode escape sequence u0043u0023 represents the characters C#.

The decision to make the C# character set conform to Unicode standards is significant. The most prevalent chara...


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
C# Development
Let Microsoft StyleCop tame your wild C#
Picking a .NET smart client communications technology
LINQ beyond queries: Strong-typed refection
Book excerpt: An introduction to DSL tools
Assembly versioning in the .NET Framework 2.0
Book excerpt: Creating graphical output using the .NET Compact Framework
On Extension Methods in C# and .NET Framework 3.5
Generate RSA public and private keys, export to XML
Book excerpt: Upgrading to Visual Studio 2005
Learning .NET: Tips for getting started with .NET development

C# programming language
Mono 2.0 moves .NET apps to Linux - includes migration analyzer
LINQ beyond queries: Strong-typed refection
Assembly versioning in the .NET Framework 2.0
Book excerpt: Creating graphical output using the .NET Compact Framework
Visual Studio 2008 Learning Guide: C# 3.0
Simonyi firm to address divide between domain experts and developers
On Extension Methods in C# and .NET Framework 3.5
Generate RSA public and private keys, export to XML
Book excerpt: Upgrading to Visual Studio 2005
Learning .NET: Tips for getting started with .NET development

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
C#  (SearchWinDevelopment.com)
GLib  (SearchWinDevelopment.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


cter set among languages has been the American Standard Code for Information Interchange (ASCII). The primary limitation of ASCII is its 8-bit character size. This doesn't accommodate multibyte character sets for various international languages. Languages such as Java were designed with the Unicode character set built-in. As the world becomes smaller, international considerations must become larger.

Identifiers can have nearly any name, but a few restrictions apply. Here are some rules to follow when creating identifiers:

  • Use nonformatting Unicode characters in any part of an identifier.
  • Identifiers can begin with an allowed Unicode character or an underline.
  • Begin an identifier with an @ symbol. This allows use of keywords as identifiers.
  • Normally, it's not permitted to use keywords as identifiers unless they're prefixed by an @ symbol. Give serious consideration before using the @ symbol because it can obfuscate code and make it confusing to read later on. There are always exceptions, but if there is a unique requirement, proceed with caution.

    Here are a few examples of legal C# identifiers:

    Now for a few examples of invalid identifiers:

    The first line is invalid because its first character is a number, which is not allowed. The first character of an identifier must be either a letter character or an underscore. The second identifier is invalid because it is a keyword. C# keywords are reserved and cannot be used as identifiers. The exception is when the keyword is prefixed with the @ character. The third line is invalid because the first character is a Unicode formatting character. Unicode formatting characters are not allowed in any part of an identifier.

    Keywords

    Keywords are words reserved by the system and have special predefined meanings when writing C# programs. The class keyword, for instance, is used to define a C# class. Another example is the void keyword, which means that a method does not return a value. These are words that are part of the language itself. Usage of keywords in any context other than what they are defined for in the C# language is likely to make code unreadable. This is the primary reason why keywords are reserved. They are meant to be used only for constructs that are part of the language.


    To read the entire article from which this tip is excerpted, click over to InformIT. You have to register there, but the registration is free.

    Rate this Tip
    To rate tips, you must be a member of SearchWinDevelopment.com.
    Register now to start rating these tips. Log in if you are already a member.




    DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



  • Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
    About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
    SEARCH 
    TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

    TechTarget Corporate Web Site  |  Media Kits  |  Site Map




    All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
      TechTarget - The IT Media ROI Experts