Common Type System in .Net

 

Identifiers: Identifiers are used to describe allocated memory types such as integer, longs, classes, and other types defined by C# or by you, as the developer. The rules for identifiers are given below.

 

1)      Identifiers can start with any Unicode letter or an underscore.

2)      Identifiers are case-sensitive.

3)      Identifiers must be unique within a particular scope: namespace, class, method, code block

 

In C# there is a defined set of naming conventions and Recommendations. The following are the two recommended naming conventions for C#:

 

1)Pascal casing: Pascal casting is the default convention for all names with the exception of protected instance fields and parameters.

 

2)Camel casing: This convention is used only for protected instance fields and parameters.

 

Open .net software following steps are needed

 

Start->programs->Microsoft visual studio 2010->Microsoft Visual studio 2010->file menu->new->

project->select visual c# from installed templates->select console application

 

Code Example: Identifiers and naming Conventions

// Adds System namespace

using System;

//Defines a new namespace

namespace Chapter1CommonTypeSystem

{

    //Defines a new class

    class MyMainClass

    {

        //Defines a static method that serves as an entry point

        //for the application

        static void Main(string[] args)

        {

            //Declares an instance of variables

            int MyInt = 10;

            long MyLong = MyInt;

            short MyShort = (short)MyInt;

            My2ndFunction(MyInt);

        }

        //defines a public static method

        public static int My2ndFunction(int myInt)

        {

            return myInt;

        }

    }

}

 

Working with pre-defined datatypes:

Datatypes are also called as primitive data types. This datatypes are divided into 4 groups.

1)Integral related datatypes: They are 8 types

Byte, SByte, short, ushort, int, uint, long, ulong.

2)Floating related datatypes:

 Float, double, decimal.

3)Character related datatypes:

 Char, string.

4)other types of datatypes:

Bool, It’s Description is true\false.

 

Code Example: Using Variables

Open console Application project

 

using System;

using System.collections;

using System.Linq;

using System.Text;

 

namespace CommonTypeSystem

{

    class program

    {

        static void Main(string[] args)

        {

            int i = 10; //value type (or) local variable

            Console.WriteLine(i);

            float x = 4.1f;

            Console.WriteLine(x);

            Byte b1 = 10, b2 = 20;

            int c = b1 + b2;

            Console.WriteLine("sum is:" + c);

            Console.ReadKey();

        }

    }

}

 

Execute the project:(goto debug menu->start debugging) (or) F5

 

Observations on above projects:

1)int i=10 local variables (value types) must be initillized before using that variable.

2)float x=4.1; gives an error.

3) + operator is used to  add the numbers and concatenate the strings

4)Console.Readkey(): holds the output screen until pressing any character in the keyboard, Which is same as getch() of c language.