In: Computer Science
with 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!
More Information: You can always read the documentation, available at https://docs.microsoft.com/en-us/dotnet/standard/base-types/composite-formatting for Composite Formatting to learn how to align text in a console application.
Your output should look something like this:
| Type | Bytes of Memory | Min | Max |
================================================
| sbyte | 1 | -128 | 127 |
| byte | 1 | 0 | 255 |
...and so on for all the types.
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} |");
}
}
}
The output is
Hope this is helpful
Please please upvote if helpful as it will help me alot
please dont downvote