Question

In: Computer Science

with C# create a console application project that outputs the number of bytes in memory that...

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.

Solutions

Expert Solution

You have to use below mentioned properties or mathods get the bytes of memory, Minimum and Maximum value of the data type:

  1. For the bytes of memory used by datatype you have to use sizeof() function that will return the size taken by the datatype.
  2. For checking minimum value of a datatype you have to use a property named MinValue as Datatype.MinValue this will return minimum value of the datatype.
  3. For checkin maximum value of a datatype you have to use a property named MaxValue as Datatype.MaxValue this will return maximum value of the datatype.
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


Related Solutions

C# Create a console application project that outputs the number of bytes in memory that each...
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 |
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression,...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a...
c# Create a console application that protects an XML file, such as the following example. Note...
c# Create a console application that protects an XML file, such as the following example. Note that the customer's credit card number and password are currently stored in clear text. The credit card must be encrypted so that it can be decrypted and used later, and the password must be salted and hashed: <?xml version="1.0" encoding="utf-8" ?> <customers> <customer> <name>Bob Smith</name> <creditcard>1234-5678-9012-3456</creditcard> <password>Pa$$w0rd</password> </customer> </customers>
C# Create a console application named that creates a list of shapes, uses serialization to save...
C# Create a console application named that creates a list of shapes, uses serialization to save it to the filesystem using XML, and then deserializes it back: // create a list of Shapes to serialize var listOfShapes = new List<Shape> { new Circle { Colour = "Red", Radius = 2.5 }, new Rectangle { Colour = "Blue", Height = 20.0, Width = 10.0 }, new Circle { Colour = "Green", Radius = 8 }, new Circle { Colour = "Purple",...
:  Create a new blank C# console application Your basal metabolic rate is the rate...
:  Create a new blank C# console application Your basal metabolic rate is the rate at which the body uses energy while at rest to keep vital functions going, such as breathing and keeping warm. This calculation is vital to weight management, as it allows you to determine calories needed to maintain, lose, or gain weight. To determine your BMR, use the appropriate formula: Female: 655+(4.35 x weight in pounds)+(4.7 x height in inches)-(4.7 x age in years) Males:...
C# Create a console application that asks the user for two numbers in the range 0-255...
C# Create a console application that asks the user for two numbers in the range 0-255 and then divides the first number by the second: Enter a number between 0 and 255: 100 Enter another number between 0 and 255: 8 100 divided by 8 is 12 Enter a number between 0 and 255: apples Enter another number between 0 and 255: bananas FormatException: Input string was not in a correct format.
Shopping Cart App (C#) Please create a C# Console (.NET Framework) application which reads from the...
Shopping Cart App (C#) Please create a C# Console (.NET Framework) application which reads from the user, the price of items in their shopping "cart". Be sure to tell the user how to stop (or ask them if they want to stop) entering prices. Items can be priced any positive number greater than zero. When the user has entered the prices for all items in their "cart", calculate the subtotal (the sum of all item prices). Next, check if the...
Create a C# Windows Console application that displays the following patterns separately, one after the other....
Create a C# Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to the next line. A statement of the form Console.Write(" "); can be used to display a space for the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT