Shallow copy in C #

I understand the definition of a shallow copy

Incorrect copying creates a new object, and then copies the non-static fields of the current object to the new object. If the field is a value type β†’ a bitwise copy of the field is executed; for the reference type β†’ the link is copied, but the mentioned object is not; therefore, the original object and its clone belong to the same object.

but why aren't static fields copied?

+5
source share
3 answers

Because static fields are not part of the object. You can access them using ClassName.StaticValue. In fact, you CANNOT access them using ClassInstanceName.StaticValue.

+8
source

Static fields are shared by all instances of a particular class.

+1

class , , , .

+1

All Articles