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

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

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