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

Methods that operate on state in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a method that operates on state in C#?
A method that operates on state is a function inside a class that changes or uses the class's fields (variables) to affect the object's data.
Click to reveal answer
beginner
Why do methods that operate on state use 'this' keyword in C#?
The 'this' keyword refers to the current object instance, helping methods access or change the object's own fields clearly.
Click to reveal answer
beginner
Example: What does this method do?
public void IncreaseAge() { age += 1; }
This method adds 1 to the 'age' field of the object, changing its state by increasing the age value.
Click to reveal answer
intermediate
What is the difference between a method that operates on state and a static method?
A method that operates on state works on an instance's data (fields), while a static method belongs to the class itself and does not use instance data.
Click to reveal answer
beginner
How do methods that operate on state help in real-life programming?
They let objects remember and change their own data, like a bank account object updating its balance when you deposit money.
Click to reveal answer
What does a method that operates on state usually do?
AOnly prints messages
BCreates new classes
CChanges or uses the object's fields
DRuns without any data
Which keyword helps a method access the current object's fields?
Astatic
Bthis
Cnew
Dvoid
What happens if a method changes a field value?
AThe object's state changes
BThe program crashes
CNothing happens
DThe method becomes static
Which method type does NOT operate on instance state?
ADestructor
BInstance method
CConstructor
DStatic method
Why are methods that operate on state useful?
AThey allow objects to update their own data
BThey make programs run faster
CThey create new objects automatically
DThey prevent any data changes
Explain what a method that operates on state is and give a simple example in C#.
Think about how an object can change its own data.
You got /3 concepts.
    Describe the difference between instance methods that operate on state and static methods.
    Consider where the method belongs and what data it can access.
    You got /3 concepts.