Identifiers and Keywords in C# Programming

Goud.Kv
Posted by in C# category on for Beginner level | Points: 250 | Views : 3565 red flag

As we know that now a days C# plays a major role in most of the Web technologies to write the server side code, Ex: ASP.NET, ASP.NET MVC etc., Lets see Language Basics of C# in this chapter.
Recommendation
Read Getting Started with Programming in C# before this article.

Introduction

Hello friends, we have seen creating a simple Hello program in C# in the previous chapter. Lets see some more language basics of C# in this chapter.

Language Basics of C#

We have already seen statement blocks, console and comments that are being used in C# in the previous chapter.

What is a source code?
-Source code is a set of files with .cs as extension. Ex: Program.cs

What is Assembly?
-Assembly is a Packaging and Deployment unit of .NET such as applications or libraries.

What is a Library?
-Library is a file without an entry point which is called(referenced) by an application or other library. These files are extended with .dll.
.NET Framework is a set of libraries.

Compilation:

C# Compiler compiles the source code into an Assembly. 'csc.exe' is the name of C# compiler. We can use IDE(Integrated Development Environment) such as Visual Studio or calling it from the command line manually.

We have already seen compiling with Visual Studio in the before chapter and if we want to compile it using command line,
  • Save a program with .cs extension such as Program.cs.

  • Now go to the Command and invoke csc which is located at,
    RootFolder(Windows Directory)\Microsoft .NET\Framework\

    i.e, csc Program.cs

  • This will create an application named Program.exe.

  • Now, do the following to create a library.
    csc /target:library Program.cs

Lets have a simple program like below to explain Identifiers and Keywords,
using System;

class Addition 
  {  
    static void Main()  
      {
        int a = 15 + 25;
        Console.WriteLine (x);
      } 
  }

In the above code, we are performing addition operation.

Identifiers:

Identifiers(names) are the being chosen by programmer for his requirements such as variablesmethodsclasses etc.

System, Addition, Main, aConsoleWriteLine, are the Identifiers in the above program.

  • Identifier must be a complete word, which is made up of Unicode characters that are started with a letter or underscore.
  • In C#, Identifiers are case-sensitive.
  • Generally, local variables, parameters and private fields should be in Camel case(Ex: myVariable) and remaining should be in Pascal case(Ex: MyMethod).

Keywords:

Keywords are the reserved names of the compiler which we can't use as Identifiers.

Using, class, static, void, int are the Keywords in the above program.

Below are the list of Keywords used in C#

abstractasbaseboolbreak
bytecasecatchcharchecked
classconstcontinuedecimaldefault
delegatedodoubleelseenum
eventexplicitexternfalsefinally
fixedfloatforforeachgoto
ifimplicitinintinterface
internalislocklongnamespace
newnullobjectoperatorout
overrideparamsprivateprotectedpublic
readonlyrefreturnsbytesealed
shortsizeofstachallocstaticstring
structswitchthisthrowtrue
trytypeofuintulongunchecked
unsafeushortusingvirtualvoid
volatilewhile




Contextual Keywords:
There are some keywords which might be used as Identifiers. Those are called as Contextual Keywords.

Below are the Contextual keywords which are also used as Identifiers
addascendingasyncawait
bydescendingdynamicequals
fromgetglobalgroup
inintojoinlet
onorderbypartialremove
selectsetvaluevar
whereyield


Conclusion

In this article, we have seen basics of C# language in which Keywords, Identifiers and Compilation. Hope you understand them clearly. If you have any doubts on this topic, please feel free to ask in the below comments.

Thanks for reading,

Regards,
Krishna.
Page copy protected against web site content infringement by Copyscape

About the Author

Goud.Kv
Full Name: Krishna Vamshi Goud
Member Level: Gold
Member Status: Member,MVP
Member Since: 2/12/2014 2:34:09 AM
Country: India
Thanks & Regards, Krishna


Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)