array of booleans?

  • Thread starter Thread starter chech
  • Start date Start date
C

chech

Possible to have array of booleans?

Dim b1 As Boolean, b2 As Boolean, b3 As Boolean
Dim obj() As Object = {b1, b2, b3}
dim v As Object
For Each v In obj
v = True
Next

This does not work. Is it possible to have an array of
booleans that can be set in a loop as above? What would
that look like?
 
This does not work. Is it possible to have an array of
booleans that can be set in a loop as above? What would
that look like?

Dim arr() As Boolean = {b1, b2, b3}
For i As Integer = 0 To arr.Length - 1
arr(i) = True
Next



Mattias
 
Dim bArray(9) As Boolean

For lCnt As Integer = 0 To bArray.Length - 1
bArray(lCnt) = True
Next lCnt

Imran.
 
Sub objthing()
Dim B1 As Boolean, B2 As Boolean, B3 As Boolean
Dim obj(2) As boolean
obj(0) = Bn1
obj(1) = Bn2
obj(2) = Bn3
Bn1 = False
For i As Integer = 0 To obj.Length - 1
obj(i) = True
Next
Console.WriteLine(Bn1) 'Bn1 is still False
End Sub

Is there some kind of structure I could place my booleans
into where I could use them in a loop as above? Would an
Arraylist work? Or some kind of pointer structure?
 
* "chech said:
Possible to have array of booleans?

In addition to the other replies: Make sure you read the documentation
on value types, reference types, and boxing.
 
Possible to have array of booleans?

Dim b1 As Boolean, b2 As Boolean, b3 As Boolean
Dim obj() As Object = {b1, b2, b3}
dim v As Object
For Each v In obj
v = True
Next

This does not work. Is it possible to have an array of
booleans that can be set in a loop as above? What would
that look like?


Option Explicit On
Option Strict On

Module Module1

Sub Main()
Dim booleans() As Boolean = {True, True, True, True, True, True}

For Each b As Boolean In booleans
Console.WriteLine(b)
Next b

For i As Integer = 0 To booleans.Length - 1
booleans(i) = False
Next i

For Each b As Boolean In booleans
Console.WriteLine(b)
Next b
End Sub

End Module
 
Back
Top