O'Reilly logo

Essential .NET, Volume 1: The Common Language Runtime by Chris Sells, Don Box

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Variables, Parameters, and Fields

Reference types always yield instances that are allocated on the heap. In contrast, value types yield instances that are allocated relevant to the context in which the variable is declared. If a local variable is of a value type, the CLR allocates the memory for the instance on the stack. If a field in a class is a member of a value type, then the CLR allocates the memory for the instance as part of the layout of the object or type in which the field is declared. The rules for dealing with value and reference types are consistent for variables, fields, and parameters. To that end, this chapter will use the term variable to refer to all three concepts and will use the term local variable when discussing variables ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required