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

Static members vs instance members in C Sharp (C#) - Interactive Practice

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

Complete the code to declare a static integer variable named count.

C Sharp (C#)
public class Counter {
    public static int [1];
}
Drag options to blanks, or click blank then click option'
Atotal
Bvalue
Ccount
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using instance variable syntax instead of static.
Choosing a variable name other than 'count'.
2fill in blank
medium

Complete the code to access the static member count from the class Counter.

C Sharp (C#)
int currentCount = Counter.[1];
Drag options to blanks, or click blank then click option'
Avalue
Bnumber
Ctotal
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access static member via an instance.
Using a wrong member name.
3fill in blank
hard

Complete the code to access the instance member value without an object.

C Sharp (C#)
public class Item {
    public int value;
}

int x = Item.[1];
Drag options to blanks, or click blank then click option'
Avalue
Bcount
Cnumber
Dtotal
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access instance members without creating an object.
Confusing static and instance members.
4fill in blank
hard

Fill both blanks to create an instance of Item and access its value member.

C Sharp (C#)
Item item = new [1]();
int val = item.[2];
Drag options to blanks, or click blank then click option'
AItem
BCounter
Cvalue
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong class name to create the object.
Trying to access static members as instance members.
5fill in blank
hard

Fill all three blanks to declare a static method that returns the static count variable.

C Sharp (C#)
public class Counter {
    public static int count;
    public static int [1]() {
        return [2].[3];
    }
}
Drag options to blanks, or click blank then click option'
AGetCount
BCounter
Ccount
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to access static variables without the class name inside static methods.
Using instance member names instead of static ones.