All jobs / Backend developer / Backend Languages

Backend developer interview question · 0–1 years

You pass a class instance and a struct to a method and both are modified inside. What does the caller see?

The strongest answer

The class change is visible because the reference points at the same object; the struct was copied, so the caller's copy is untouched unless it was passed with ref

Why it works

Exactly. Reference types share the object, value types are copied.

What a good answer covers

Answers that fall short

Who gets asked this

More Backend Languages questions