0% found this document useful (0 votes)
9 views3 pages

Byte and Data Type Ranges in C#

The document is a C# program that demonstrates the use of various data types including byte, sbyte, short, ushort, int, uint, long, ulong, float, double, and decimal. It provides examples of their minimum and maximum values, along with compile-time error comments for invalid assignments. Additionally, it covers scientific notation and hexadecimal/binary representations.

Uploaded by

ismailah21645
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Byte and Data Type Ranges in C#

The document is a C# program that demonstrates the use of various data types including byte, sbyte, short, ushort, int, uint, long, ulong, float, double, and decimal. It provides examples of their minimum and maximum values, along with compile-time error comments for invalid assignments. Additionally, it covers scientific notation and hexadecimal/binary representations.

Uploaded by

ismailah21645
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//ProgrammingAdvices.

com
//Mohammed Abu-Hadhoud

using System;

namespace Main
{
internal class Program
{
static void Main(string[] args)
{

//Byte

byte b1 = 255;
// byte b2 = -128;// compile-time error: Constant value '-128' cannot be
converted to a 'byte'
sbyte sb1 = -128;
sbyte sb2 = 127;
[Link]("\nByte:");
[Link]("Min={0} , Max={1}", [Link], [Link]);

[Link]("\nSByte:");
[Link]("Min={0} , Max={1}", [Link], [Link]);

//Short
short s1 = -32768;
short s2 = 32767;
// short s3 = 35000;//Compile-time error: Constant value '35000' cannot
be converted to a 'short'

ushort us1 = 65535;


// ushort us2 = -32000; //Compile-time error: Constant value '-32000'
cannot be converted to a 'ushort'

[Link]("\nShort:");
[Link]("Min={0} , Max={1}", [Link], [Link]);

[Link]("\nUShort:");
[Link]("Min={0} , Max={1}", [Link],
[Link]);

//int
int i = -2147483648;
int j = 2147483647;
// int k = 4294967295; //Compile-time error: Cannot implicitly convert
type 'uint' to 'int'.

uint ui1 = 4294967295;


// uint ui2 = -1; //Compile-time error: Constant value '-1' cannot be
converted to a 'uint'

[Link]("\nInt:");
[Link]("Min={0} , Max={1}", [Link], [Link]);

[Link]("\nUInt:");
[Link]("Min={0} , Max={1}", [Link],
[Link]);

//Long
long l1 = -9223372036854775808;
long l2 = 9223372036854775807;

ulong ul1 = 18223372036854775808ul;


ulong ul2 = 18223372036854775808UL;

[Link]("\nLong:");
[Link]("Min={0} , Max={1}", [Link], [Link]);

[Link]("\nULong:");
[Link]("Min={0} , Max={1}", [Link],
[Link]);

//Float
float f1 = 123456.5F;
float f2 = 1.123456f;

[Link]("\nFloat:");
[Link]("Min={0} , Max={1}", [Link], [Link]);

//double
double d1 = 12345678912345.5d;
double d2 = 1.123456789123456d;

[Link]("\nDouble:");
[Link]("Min={0} , Max={1}", [Link],
[Link]);

//Decimal
//The decimal type has more precision and a smaller range
//than both float and double,
//and so it is appropriate for financial and monetary calculations.
decimal d3 = 123456789123456789123456789.5m;
decimal d4 = 1.1234567891345679123456789123m;

[Link]("\nDecimal:");
[Link]("Min={0} , Max={1}", [Link],
[Link]);

//Scientific Notation
//Use e or E to indicate the power of 10
//as exponent part of scientific notation with float, double or
decimal.

double d = 0.12e2;
[Link](d); // 12;

float f = 123.45e-2f;
[Link](f); // 1.2345

decimal m = 1.2e6m;
[Link](m);// 1200000

//hex & Binary


int hex = 0x2F;
int binary = 0b_0010_1111;

[Link](hex);
[Link](binary);

[Link]();

}
}
}

You might also like