O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

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

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. ...

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