Difference between data type of C# and data type .NET framework

Sourav.Kayal
Posted by in C# category on for Beginner level | Points: 250 | Views : 2265 red flag

In this article we will see how data type of C# converts into data type of .NET

Difference between data type of C# and data type .NET framework

In this article we will try to understand the difference between data type of C# and data type of .NET framework. We all know that .NET framework supports nearly 32 programming languages to develop application. And each programming language has it’s own data type , for example in C# programming language “Int” is present where in PHP everything is represented by “var” because PHP is loosely type checking programming language.

So, whatever programming language we may use in .NET platform , ultimately they converts in .NET framekork’s own data type.

For example, if we use “int” to define integer in C# ,after compilation the code it will convert to “Int32” which is data type of .NET framework.  Another example is “String” and “string” String is data type of C# but string is data type of .NET framework.  We will see them by example.

Check with "int" and "Int32"
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 100;
            Int32 b = 100;
            Console.ReadLine();
        }
    }
}

In this example we have defined a as int variable and b as Int32 data type. Now we will build the application and we will open the code in ILDASM. Here is output of ILDASM


 

We are seeing that both int and Int32 has converted into Int32 data type. So, both has converted into .NET framework’s data type.


Check with “string” and “String”

Now we will check with “string” and “String” . As we discuss earlier the “string” is data type of .NET framework and “String” is data type of C# programming language and ultimately “String” will convert into “string”. Let’s see by example.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string name1 = "TestString";
            String name2 = "TestString";
            Console.ReadLine();
        }
    }
}

In this example the name1 was declared as “string” and name2 has declared as “String” and here is ILDASM output.


 

We are seeing that “String” has converted into “string” after compilation. This happens in case of all data type. So, the concept is ultimately everything converts into .NET framework’s data type.

  

Test with "var"

As we know var keyword supports all data type and after compilation it converts in appropriate data type. In below example we will test var keyword.

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = "sourav kayal";
            var b = 100;
            Console.ReadLine();
        }
    }
}

 

At first we have initialized string into var and then we have initialize int into var and here is output in ILDASM.

 

We are seeing that the first var has converted into “string” and second one is into “Int32”


Conclusion:-

In this article we have learned how C# data type converts in .NET framework’s data type. Hope you have understood the concept and enjoyed the article.

 

 

Page copy protected against web site content infringement by Copyscape

About the Author

Sourav.Kayal
Full Name: Sourav Kayal
Member Level: Silver
Member Status: Member,MVP
Member Since: 6/20/2013 2:09:01 AM
Country: India
Read my blog here http://ctrlcvprogrammer.blogspot.in/
http://www.dotnetfunda.com
I am .NET developer working for HelixDNA Technologies,Bangalore in healthcare domain. Like to learn new technology and programming language. Currently working in ASP.NET ,C# and other microsoft technologies.

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)