X hits on this document

863 views

0 shares

0 downloads

0 comments

280 / 396

Chapter ‎18   Unsafe code

public static DBBool operator !=(DBInt x, DBInt y) { return x.defined && y.defined? x.value != y.value: DBBool.Null; }

public static DBBool operator >(DBInt x, DBInt y) { return x.defined && y.defined? x.value > y.value: DBBool.Null; }

public static DBBool operator <(DBInt x, DBInt y) { return x.defined && y.defined? x.value < y.value: DBBool.Null; }

public static DBBool operator >=(DBInt x, DBInt y) { return x.defined && y.defined? x.value >= y.value: DBBool.Null; }

public static DBBool operator <=(DBInt x, DBInt y) { return x.defined && y.defined? x.value <= y.value: DBBool.Null; }

public override bool Equals(object obj) { if (!(obj is DBInt)) return false; DBInt x = (DBInt)obj; return value == x.value && defined == x.defined; }

public override int GetHashCode() { return value; }

public override string ToString() { return defined? value.ToString(): “DBInt.Null”; } }

11.4.2 Database boolean type

The DBBool struct below implements a three-valued logical type. The possible values of this type are DBBool.True, DBBool.False, and DBBool.Null, where the Null member indicates an unknown value. Such three-valued logical types are commonly used in databases.

using System;

public struct DBBool { // The three possible DBBool values.

public static readonly DBBool Null = new DBBool(0); public static readonly DBBool False = new DBBool(-1); public static readonly DBBool True = new DBBool(1);

// Private field that stores –1, 0, 1 for False, Null, True.

sbyte value;

// Private instance constructor. The value parameter must be –1, 0, or 1.

DBBool(int value) { this.value = (sbyte)value; }

// Properties to examine the value of a DBBool. Return true if this // DBBool has the given value, false otherwise.

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

Document info
Document views863
Page views863
Page last viewedMon Dec 05 13:23:49 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments