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

Assignment and compound assignment 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 assign the value 10 to the variable number.

C Sharp (C#)
int number [1] 10;
Drag options to blanks, or click blank then click option'
A=
B==
C+=
D=>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '=' causes a syntax error.
Using '+=' without initializing the variable first.
2fill in blank
medium

Complete the code to add 5 to the variable score using a compound assignment operator.

C Sharp (C#)
score [1] 5;
Drag options to blanks, or click blank then click option'
A*=
B+=
C-=
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' only replaces the value instead of adding.
Using '-=' subtracts instead of adding.
3fill in blank
hard

Fix the error in the code to multiply count by 3 using a compound assignment.

C Sharp (C#)
count [1] 3;
Drag options to blanks, or click blank then click option'
A*=
B==
C=
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' alone causes a syntax error.
Using '=' only assigns without multiplying.
4fill in blank
hard

Complete the code: first initialize value to 2, then subtract 2 from it using a compound assignment operator.

C Sharp (C#)
value [1] 2;
value [2] 2;
Drag options to blanks, or click blank then click option'
A-=
B=
C+=
D*=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' instead of '-=' for subtraction.
Using '=' for both lines causes no subtraction.
5fill in blank
hard

Fill all three blanks to add each word to the dictionary `lengths` mapping it to its length, but only if the length is greater than 3. Assume `word` is a string variable in scope.

C Sharp (C#)
var lengths = new Dictionary<string, int>();
if ([1] > 3) {
    lengths[[2]] = [3];
}
Drag options to blanks, or click blank then click option'
A"word"
B"word".Length
Cword.Length
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using quoted strings instead of the variable word for keys.
Forgetting to use word.Length and using a string literal.