In: Computer Science
C#
Create a console application project that outputs the number of bytes in memory that each of the following number types use, and the minimum and maximum values they can have: sbyte, byte, short, ushort, int, uint, long, ulong, float, double, and decimal.
Try formatting the values into a nice-looking table!
Your output should look something like this:
| Type | Bytes of Memory | Min | Max |
You have to use below mentioned properties or mathods get the bytes of memory, Minimum and Maximum value of the data type:
using System;
namespace Package1
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("| Type | Bytes of Memory | Min | Max |");
Console.WriteLine($"| sbyte | {sizeof(sbyte)} | {sbyte.MinValue} | {sbyte.MaxValue} |");
Console.WriteLine($"| byte | {sizeof(byte)} | {byte.MinValue} | {byte.MaxValue} |");
Console.WriteLine($"| short | {sizeof(short)} | {short.MinValue} | {short.MaxValue} |");
Console.WriteLine($"| ushort | {sizeof(ushort)} | {ushort.MinValue} | {ushort.MaxValue} |");
Console.WriteLine($"| int | {sizeof(int)} | {int.MinValue} | {int.MaxValue} |");
Console.WriteLine($"| uint | {sizeof(uint)} | {uint.MinValue} | {uint.MaxValue} |");
Console.WriteLine($"| long | {sizeof(long)} | {long.MinValue} | {long.MaxValue} |");
Console.WriteLine($"| ulong | {sizeof(ulong)} | {ulong.MinValue} | {ulong.MaxValue} |");
Console.WriteLine($"| float | {sizeof(float)} | {float.MinValue} | {float.MaxValue} |");
Console.WriteLine($"| double | {sizeof(double)} | {double.MinValue} | {double.MaxValue} |");
Console.WriteLine($"| decimal | {sizeof(decimal)} | {decimal.MinValue} | {decimal.MaxValue} |");
}
}
}