X hits on this document





42 / 396

Chapter ‎18   Unsafe code

public class EditBox: IControl, IDataBound { void IControl.Paint() {...}

void IDataBound.Bind(Binder b) {...} }

Explicit interface members can only be accessed via the interface type. For example, the implementation of IControl.Paint provided by the previous EditBox class can only be invoked by first converting the EditBox reference to the IControl interface type.

EditBox editBox = new EditBox(); editBox.Paint();// Error, no such method IControl control = editBox; control.Paint();// Ok

1.10 Enums

An enum type is a distinct value type with a set of named constants. The following example declares and uses an enum type named Color with three constant values, Red, Green, and Blue.

using System;

enum Color { Red,   Green,   Blue }

class Test { static void PrintColor(Color color) { switch (color) { case Color.Red: Console.WriteLine("Red"); break; case Color.Green: Console.WriteLine("Green"); break; case Color.Blue: Console.WriteLine("Blue"); break; default: Console.WriteLine("Unknown color"); break; } }

static void Main() { Color c = Color.Red; PrintColor(c); PrintColor(Color.Blue); } }

Each enum type has a corresponding integral type called the underlying type of the enum type. An enum type that does not explicitly declare an underlying type has an underlying type of int. An enum type’s storage format and range of possible values are determined by its underlying type. The set of values that an enum type can take on is not limited by its enum members. In particular, any value of the underlying type of an enum can be cast to

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.29

Document info
Document views1242
Page views1242
Page last viewedFri Jan 20 00:15:06 UTC 2017