What is a Value Class and what is a reference Class in C#?

后端 未结 7 2032
刺人心
刺人心 2020-12-11 17:44

What is the definition of a value class and reference class in C#?

How does this differ from a value type and reference

7条回答
  •  天涯浪人
    2020-12-11 17:49

    Reference types are passed to methods by reference and value types by value; in the latter case a method receives a copy of the variable and in the former it receives a reference to the original data. If you change your copy, the original does not change. If you change the original data you have a reference to, the data changes everywhere a reference to the data is changed. If a similar program to your C# program was created in C, generally reference types would be like data using pointers and value types would be normal data on the stack.

    Numeric types, char, date, enumerations, and structures are all value types. Strings, arrays, delegates and classes (i.e., most things, really) are reference types.

提交回复
热议问题