Declaring Fields

To declare a field, you must specify at least a type and a field name. Multiple fields with the same type can be put on a single line in a comma-separated manner, just like you can do for variables within a code block. Here, some instance and static fields are declared on a Person class:

class Person{    private static int s_population;    private string _name;    private int _age;}

By default, fields are private, regardless of whether the containing type is a struct or a class. This differs from C++, where classes and structs don’t relate to the allocation location of objects but instead determine the default visibility of members. It’s deemed good style to be explicit about visibility, though. ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.