Q:

C# | print type, max and min value of various data types

belongs to collection: C# Basic Programs | basics

0

C# | print type, max and min value of various data types

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataTypes
{
	class MyDataType
	{
		public string Show()
		{
			return ("MyType");
		}
	}
	class Program
	{
		static void Main(string[] args)
		{
			Console.WriteLine("VALUE TYPE:");
			Console.WriteLine("---------------------------------------------");
			Console.WriteLine("Integers:");
			byte a = 12;
			Console.WriteLine("byte\tA = {0}\t{1}\t{2}\t{3}", a, typeof(byte), byte.MaxValue, byte.MinValue);
			sbyte b = 12;
			Console.WriteLine("sbyte\tB = {0}\t{1}\t{2}\t{3}", b, typeof(sbyte), sbyte.MaxValue, sbyte.MinValue);
			short c = 12;
			Console.WriteLine("short\tC = {0}\t{1}\t{2}\t{3}", c, typeof(short), short.MaxValue, short.MinValue);
			ushort d = 12;
			Console.WriteLine("ushort\tD = {0}\t{1}\t{2}\t{3}", d, typeof(ushort), ushort.MaxValue, ushort.MinValue);
			int e = 12;
			Console.WriteLine("int\tE = {0}\t{1}\t{2}\t{3}", e, typeof(int), int.MaxValue, int.MinValue);
			uint f = 12;
			Console.WriteLine("unit\tF = {0}\t{1}\t{2}\t{3}", f, typeof(uint), uint.MaxValue, uint.MinValue);
			long g = 12;
			Console.WriteLine("long\tG = {0}\t{1}\t{2}\t{3}", g, typeof(long), long.MaxValue, long.MinValue);
			ulong h = 12;
			Console.WriteLine("ulong\tH = {0}\t{1}\t{2}\t{3}", h, typeof(ulong), ulong.MaxValue, ulong.MinValue);

			Console.WriteLine("\nFloating Point:");
			float i = 123.34f;
			Console.WriteLine("float\tI = {0}\t{1}\t{2}\t{3}", i, typeof(float), float.MaxValue, float.MinValue);
			double j = 123.34;
			Console.WriteLine("double\tJ = {0}\t{1}\t{2}\t{3}", j, typeof(double), double.MaxValue, double.MinValue);
			decimal k = 123.34m;
			Console.WriteLine("decimal\tK = {0}\t{1}\t{2}\t{3}", k, typeof(decimal), decimal.MaxValue, decimal.MinValue);

			Console.WriteLine("\nText:");
			char l = 'f';
			Console.WriteLine("char\tL = {0}\t{1}", l, typeof(char));

			Console.WriteLine("\nBoolean:");
			bool m = true;
			Console.WriteLine("bool\tM = {0}\t{1}", m, typeof(bool));

			Console.WriteLine("\nREFERENCE TYPE:");
			Console.WriteLine("---------------------------------------------");
			string n = "Hello";
			Console.WriteLine("string\tn = {0}\t{1}", n, typeof(string));
			object o = 12.34;
			Console.WriteLine("object\tn = {0}\t{1}", o, typeof(object));
			MyDataType p = new MyDataType();
			Console.WriteLine("MyDataType\tp = {0}\t{1}", p.Show(), typeof(MyDataType));
			int[] q = { 12, 45, 56 };
			Console.WriteLine("int[]\tq = {0}",typeof(int[]));

			Console.WriteLine("\nNullable TYPE:");
			Console.WriteLine("---------------------------------------------");
			string r = null;
			Console.WriteLine("string\tr = {0}\t{1}", r, typeof(string));
			int? s = null;
			Console.WriteLine("int\ts = {0}\t{1}", s, typeof(int?));

			Console.ReadKey();
		}
	}
}

Output

VALUE TYPE:
---------------------------------------------
Integers:
byte    A = 12  System.Byte     255     0
sbyte   B = 12  System.SByte    127     -128
short   C = 12  System.Int16    32767   -32768
ushort  D = 12  System.UInt16   65535   0
int     E = 12  System.Int32    2147483647      -2147483648
unit    F = 12  System.UInt32   4294967295      0
long    G = 12  System.Int64    9223372036854775807     -9223372036854775808
ulong   H = 12  System.UInt64   18446744073709551615    0

Floating Point:
float   I = 123.34      System.Single   3.402823E+38    -3.402823E+38
double  J = 123.34      System.Double   1.79769313486232E+308   -1.79769313486232E+308
decimal K = 123.34      System.Decimal  79228162514264337593543950335   -79228162514264337593543950335

Text:
char    L = f   System.Char

Boolean:
bool    M = True        System.Boolean

REFERENCE TYPE:
---------------------------------------------
string  n = Hello       System.String
object  n = 12.34       System.Object
MyDataType      p = MyType      DataTypes.MyDataType
int[]   q = System.Int32[]

Nullable TYPE:
---------------------------------------------
string  r =     System.String
int     s =     System.Nullable`1[System.Int32]

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to swap numbers using XOR operator... >>
<< C# program to swap two numbers with and without us...