0
0
C Sharp (C#)programming~10 mins

Integer types and their ranges in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a variable of type int with the value 100.

C Sharp (C#)
int number = [1];
Drag options to blanks, or click blank then click option'
A100
B"100"
C100.0
D'100'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, which makes it a string.
Using a decimal point, which makes it a floating-point number.
2fill in blank
medium

Complete the code to print the maximum value of a byte type.

C Sharp (C#)
Console.WriteLine(byte.[1]);
Drag options to blanks, or click blank then click option'
AMaxValue
BMinValue
CMax
DMaximum
Attempts:
3 left
💡 Hint
Common Mistakes
Using MinValue instead of MaxValue.
Using incorrect property names like Max or Maximum.
3fill in blank
hard

Fix the error in the code by choosing the correct type for a large integer value.

C Sharp (C#)
long bigNumber = [1];
Drag options to blanks, or click blank then click option'
A2147483649L
B2147483648
C2147483648L
D2147483647
Attempts:
3 left
💡 Hint
Common Mistakes
Not adding 'L' suffix for long literals.
Using values within int range without suffix.
4fill in blank
hard

Fill both blanks to create a dictionary mapping integer types to their size in bytes.

C Sharp (C#)
var sizes = new Dictionary<string, int> { {"int", [1], {"long", [2] };
Drag options to blanks, or click blank then click option'
A4
B8
C2
D16
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing the sizes of int and long.
Using sizes for other types like short or byte.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps integer types to their max values if the max value is greater than 1000.

C Sharp (C#)
var maxValues = new Dictionary<string, long> { {"int", [1], {"short", [2], {"long", [3] }.Where(kv => kv.Value > 1000).ToDictionary(kv => kv.Key, kv => kv.Value);
Drag options to blanks, or click blank then click option'
Aint.MaxValue
Bshort.MaxValue
Clong.MaxValue
Dbyte.MaxValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using byte.MaxValue which is less than 1000.
Not using the MaxValue property.