站内搜索: 请输入搜索关键词
当前页面: 图书首页 > NET For Java Developers Migrating To C#

NET For Java Developers Migrating To C#

[ directory ] Previous Section Next Section

7.5 The C# Reference Types

Reference types store references to actual data. In C#, reference types fall into the following categories:

  • class

  • interface

  • delegate

The class and interface keywords should be intuitive. They are used to define classes and interfaces, respectively. The delegate keyword is used to define references to a function (see Chapter 18). When you instantiate a delegate with parameters passed to it, that calls the underlying function to which the delegate is pointing. The two commonly used classes in the .NET Framework are System.Object and System.String. Their aliases are object and string, respectively. All data types inherit from System.Object. This inheritance enables value types (known as primitives in Java) to be treated as objects in C#. Value types梚ncluding both struct types and built-in types such as int梒an be converted to and from the type object. As mentioned in Chapter 3, this conversion is transparent to the programmer and is called boxing and unboxing. The following section discusses this process in detail.

    [ directory ] Previous Section Next Section