Sobes.tech
Junior — Middle

Can you give an example of an operation or method that gives the same result regardless of how many times it is called?

sobes.tech AI

Answer from AI

Operations or methods that produce the same result regardless of the number of calls are called idempotent.

An example in C# is a method that sets the value of a property:

class Counter
{
    public int Value { get; private set; }

    public void SetValue(int newValue)
    {
        Value = newValue; // Idempotent operation
    }
}

Calling SetValue(5) multiple times will always result in the same state — Value will be 5.

Another example is the HTTP PUT method, which updates a resource to a specific state, regardless of the number of calls.