13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8 <strong>Language</strong> OverviewDevelopers can define new value types through enum and struct declarations, and can define new referencetypes via class, interface, and delegate declarations. The exampleusing System;public enum Color{Red, Blue, Green}public struct Point{public int x, y;}public interface IBase{void F();}public interface IDerived: IBase{void G();}public class A{protected virtual void H() {Console.WriteLine("A.H");}}public class B: A, IDerived{public void F() {Console.WriteLine("B.F, implementation of IDerived.F");}public void G() {Console.WriteLine("B.G, implementation of IDerived.G");}override protected void H() {Console.WriteLine("B.H, override of A.H");}}public delegate void EmptyDelegate();shows an example of each kind of type declaration. Later sections describe type declarations in detail.8.2.1 Predefined types<strong>C#</strong> provides a set of predefined types, most of which will be familiar to C and C++ developers.The predefined reference types are object and string. The type object is the ultimate base type of allother types. The type string is used to represent Unicode string values. Values of type string areimmutable.The predefined value types include signed and unsigned integral types, floating-point types, and the typesbool, char, and decimal. The signed integral types are sbyte, short, int, and long; the unsignedintegral types are byte, ushort, uint, and ulong; and the floating-point types are float and double.The bool type is used to represent boolean values: values that are either true or false. The inclusion of boolmakes it easier to write self-documenting code, and also helps eliminate the all-too-common C++ codingerror in which a developer mistakenly uses “=” when “==” should have been used. In <strong>C#</strong>, the exampleint i = …;F(i);if (i = 0) // Bug: the test should be (i == 0)G();17

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!