Aave
Aave

Reputation: 568

VB.NET: How init bool array with true

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

Answers (2)

the_lotus
the_lotus

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

Matteo Marciano - MSCP
Matteo Marciano - MSCP

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

Related Questions