Ternary Datatype : True, False, Null 
Author Message
 Ternary Datatype : True, False, Null

Is there a .NET datatype to use which is essentially a boolean but can also
take a 3rd state of being neither (Null - or 'mu')?

Sometimes I find myself wanting to do this.  Especially with procedure
return values.
Thanks....

--
Phil (New Zealand - Aotearoa)



Wed, 29 Dec 2004 10:34:08 GMT  
 Ternary Datatype : True, False, Null


Quote:
>Is there a .NET datatype to use which is essentially a boolean but can also
>take a 3rd state of being neither (Null - or 'mu')?

You could certain create such a thing, see below.  However my experience has
been that it's better to change the design such that tristate values are not
used.

Namespace Test
    _
   Enum TristateValue
      Yes
      No
      Undecided
   End Enum 'TristateValue
    _

   Class Class1

      'Entry point which delegates to C-style main Private Function
      Public Overloads Shared Sub Main()
         Main(System.Environment.GetCommandLineArgs())
      End Sub

      Overloads Shared Sub Main(args() As String)
         Select Case foo()
            Case TristateValue.Yes
               Console.WriteLine("yes")
            Case TristateValue.No
               Console.WriteLine("no")
            Case TristateValue.Undecided
               Console.WriteLine("undecided")
         End Select
         Console.ReadLine()
      End Sub 'Main

      Shared Function foo() As TristateValue
         Return TristateValue.Yes
      End Function 'foo
   End Class 'Class1
End Namespace 'Test

--

*--------={ Fine Art for .NET }=--------*

*---------------------------------------*

       Turn on, tune in, download.



Wed, 29 Dec 2004 10:39:01 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Ternary Datatype : True, False, Null

2. Using True/False fields in DCOUNT

3. Warnings False Causes GPF True doesn't???

4. Question from VBA novice re True and False values in VBA code for Word97

5. Disable checkbox true/false?

6. Evaluate Contents of a String to True or False

7. Evaluating a string as True/False without cooersion

8. True or false, 0 or -1 ???

9. TRUE and FALSE or 0 and -1 confused!!

10. true and false as numbers

11. Accessing true/false data from VB 6

12. DataField true/false display

 

 
Powered by phpBB® Forum Software