當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET BitArray.SetAll方法代碼示例

本文整理匯總了VB.NET中System.Collections.BitArray.SetAll方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET BitArray.SetAll方法的具體用法?VB.NET BitArray.SetAll怎麽用?VB.NET BitArray.SetAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Collections.BitArray的用法示例。


在下文中一共展示了BitArray.SetAll方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Main

' 導入命名空間
Imports System.Collections

Public Class SamplesBitArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a BitArray.
        Dim myBA As New BitArray(5)
        
        ' Displays the properties and values of the BitArray.
        Console.WriteLine("myBA values:")
        PrintIndexAndValues(myBA)
        
        ' Sets all the elements to true.
        myBA.SetAll(True)
        
        ' Displays the properties and values of the BitArray.
        Console.WriteLine("After setting all elements to true,")
        PrintIndexAndValues(myBA)
        
        ' Sets the last index to false.
        myBA.Set(myBA.Count - 1, False)
        
        ' Displays the properties and values of the BitArray.
        Console.WriteLine("After setting the last element to false,")
        PrintIndexAndValues(myBA)
        
        ' Gets the value of the last two elements.
        Console.WriteLine("The last two elements are: ")
        Console.WriteLine("    at index {0} : {1}", _
           myBA.Count - 2, myBA.Get(myBA.Count - 2))
        Console.WriteLine("    at index {0} : {1}", _
           myBA.Count - 1, myBA.Get(myBA.Count - 1))
    End Sub

    Public Shared Sub PrintIndexAndValues(myCol As IEnumerable)
        Dim i As Integer
        Dim obj As Object
        i = 0
        For Each obj In  myCol
            Console.WriteLine("    [{0}]:    {1}", i, obj)
            i = i + 1
        Next obj
        Console.WriteLine()
    End Sub

End Class
開發者ID:VB.NET開發者,項目名稱:System.Collections,代碼行數:48,代碼來源:BitArray.SetAll

輸出:

myBA values:
[0]:    False
[1]:    False
[2]:    False
[3]:    False
[4]:    False

After setting all elements to true,
[0]:    True
[1]:    True
[2]:    True
[3]:    True
[4]:    True

After setting the last element to false,
[0]:    True
[1]:    True
[2]:    True
[3]:    True
[4]:    False

The last two elements are:
at index 3 : True
at index 4 : False


注:本文中的System.Collections.BitArray.SetAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。