Reputation: 568
Is it possible create and initialize array of boolean with True in vb.net at one action (without cycle assignement)? By default array initialized by False. I need opposing.
Upvotes: 1
Views: 5258
Reputation: 12748
You could use a BitArray which support only True and False. The constructor let you initialize it.
Dim b As New BitArray(1000, True)
Console.WriteLine(b(10)) ' Display True
It should take less memory also.
Upvotes: 4
Reputation: 439
You can use Linq method Repeat(Of TResult) to achieve such task in the shortest way, without defining any custom function.
Dim myArray = Enumerable.Repeat(Of Boolean)(True, 10000).ToArray()
Upvotes: 2