1.14. The Unified Type System

When we define an object, we must specify its type. The type determines the kind of values the object can hold and the permissible range of those values. For example, byte is an unsigned integral type with a size of 8 bits. The definition

byte b;

declares that b can hold integral values, but that those values must be within the range of 0 to 255. If we attempt to assign b a floating-point value:

b = 3.14159;  // compile-time error

a string value:

b = "no way"; // compile-time error

or an integer value outside its range:

b = 1024;     // compile-time error

each of those assignments is flagged as a type error by the compiler. This is true of the C# array type as well. So why is an ArrayList container able to hold ...

Get C# Primer: A Practical Approach 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.