concept field in category c#

appears as: field, fields, fields, field
C# in Depth, Fourth Edition

This is an excerpt from Manning's book C# in Depth, Fourth Edition.

I’d expect the size of a value of this struct type to be 24 bytes or possibly 32 bytes if the runtime aligned the fields to 8-byte boundaries. The important point is that all of the data is directly within the value; there’s no reference to a separate byte array. This struct could be used for interoperability with native code or just used within regular managed code.

Figure 13.6. At the end of listing 13.4, the tmp variable refers to a field in the first instance created, whereas the value of obj refers to a different instance.

There are a couple of final points to make about local methods and variables, but this time the variables under discussion are not captured variables but fields.

14.8.3. Attributes for fields backing automatically implemented properties

Suppose you want a trivial property backed by a field, but you need to apply an attribute to the field to enable other infrastructure. Prior to C# 7.3, you’d have to declare the field separately and then write a simple property with boilerplate code. For example, suppose you wanted to apply a DemoAttribute (just an attribute I’ve made up) to a field backing a string property. You’d have needed code like this:

[field: Demo]
public string Name { get; set; }


!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":13}]]"}
!@%STYLE%@!