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

Implicit typing with var keyword 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 an implicitly typed variable holding the number 10.

C Sharp (C#)
var number = [1];
Drag options to blanks, or click blank then click option'
A"10"
Bnumber
C10
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around 10 makes it a string, not an int.
Trying to assign 'var' as a value is incorrect.
2fill in blank
medium

Complete the code to declare an implicitly typed variable holding the text "hello".

C Sharp (C#)
var greeting = [1];
Drag options to blanks, or click blank then click option'
A"hello"
Bhello
C'hello'
Dgreeting
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes for strings is invalid in C#.
Not using quotes makes the compiler think it's a variable name.
3fill in blank
hard

Fix the error in the code by completing the declaration of an implicitly typed variable holding a decimal number.

C Sharp (C#)
var price = [1]m;
Drag options to blanks, or click blank then click option'
A19.99
B19,99
C"19.99"
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of dots for decimals.
Putting the number in quotes makes it a string, not a decimal.
4fill in blank
hard

Complete the code to declare an implicitly typed variable holding a list of integers and initialize it with values 1, 2, and 3.

C Sharp (C#)
var numbers = new [1]<int> {1, 2, 3};
Drag options to blanks, or click blank then click option'
A()
BList
C[]
DArray
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces for initialization.
Using 'Array' without proper syntax for initialization.
5fill in blank
hard

Complete the code to declare an implicitly typed variable holding a dictionary with string keys and int values, initialized with two entries.

C Sharp (C#)
var ages = new Dictionary<[1], [2]> { {"Alice", 30}, {"Bob", 25} };
Drag options to blanks, or click blank then click option'
Astring
Bint
C{}
D[]
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of curly braces for initialization.
Mixing up key and value types.