Code and Data

Think of types as entities containing code/data. You can consider data to be the most important part here, based on object-oriented considerations and whatnot. Given a set of primitive types, as you’ll see in just a minute, new types can be defined. On the field of data, defining a type can be seen as an act of composition.

For example, to represent a person object, you could define a Person class type containing fields to hold the relevant data:

class Person{    private string _name;    private int _age;    public Person(string name, int age)    {        _name = name;        _age = age;    }    public void Print()    {        Console.WriteLine(_name + " is " + _age + " years young");    }}

In this ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.