MOCKSTACKS
EN
Questions And Answers

More Tutorials








C# Data Types

Like many other programming languages, C# does support multiple Data types below table show the most commonly used data types:

Data TypeSizestyle="width:63%">Description
int4 bytesNumbers from -2,147,483,648 to 2,147,483,647
long8 bytesNumbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float4 bytesfractional numbers. Sufficient for storing 6 to 7 decimal digits
double8 bytesfractional numbers. Sufficient for storing 15 decimal digits
bool1 bittrue or false values
char2 bytesSingle character/letter, surrounded by single quotes
string2 bytes per characterSequence of characters surrounded by double quotes


C# int example

In C# we can define an integer using int keyword

using System;

namespace Application
{
  class Program
  {
    static void Main(string[] args)
    {
      int newNum= 500;
      Console.WriteLine(newNum);
    }
  }
}

Output

500

C# long example

In C# we can define a Long using long keyword

using System;

namespace Application
{
  class Program
  {
    static void Main(string[] args)
    {
      long longNum = 90000000000L;
      Console.WriteLine(longNum);
    }
  }
}

Output

90000000000

C# float example

In C# we can define a float using float keyword

using System;

namespace Application
{
  class Program
  {
    static void Main(string[] args)
    {
      float floatNum = 0.99F;
      Console.WriteLine(floatNum);
    }
  }
}

Output

0.99

C# double example

In C# we can define a double using double keyword

using System;

namespace Application
{
  class Program
  {
    static void Main(string[] args)
    {
      double floatNum = 20.99D;
      Console.WriteLine(floatNum);
    }
  }
}

Output

20.99

C# bool example

In C# we can define a boolean using bool keyword

using System;

namespace Application
{
  class Program
  {
    static void Main(string[] args)
    {
      bool isTrueBoolean = true;
      Console.WriteLine(isTrueBoolean);
    }
  }
}

Output

True

C# char example

In C# we can define a char using char keyword

using System;

namespace Application
{
  class Program
  {
    static void Main(string[] args)
    {
      char myGrade = 'B';
      Console.WriteLine(myGrade );
    }
  }
}

Output

B

C# string example

In C# we can define a string using string keyword

using System;

namespace Application
{
  class Program
  {
    static void Main(string[] args)
    {
      string helloWorldMessage= "Hello World";
      Console.WriteLine(helloWorldMessage);
    }
  }
}

Output

Hello World

Conclusion

In this page (written and validated by ) you learned about C# Data Types . What's Next? If you are interested in completing CS tutorial, your next topic will be learning about: CS Declare a variable.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.