当前位置: 首页>>代码示例>>C#>>正文


C# BitArray.Set方法代码示例

本文整理汇总了C#中System.Collections.BitArray.Set方法的典型用法代码示例。如果您正苦于以下问题:C# BitArray.Set方法的具体用法?C# BitArray.Set怎么用?C# BitArray.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.BitArray的用法示例。


在下文中一共展示了BitArray.Set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

//引入命名空间
using System;
using System.Collections;
public class SamplesBitArray  {

   public static void Main()  {

      // Creates and initializes a BitArray.
      BitArray myBA = 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 ) );
   }

   public static void PrintIndexAndValues( IEnumerable myCol )  {
      int i = 0;
      foreach ( Object obj in myCol ) {
         Console.WriteLine( "    [{0}]:    {1}", i++, obj );
      }
      Console.WriteLine();
   }
}
开发者ID:.NET开发者,项目名称:System.Collections,代码行数:42,代码来源:BitArray.Set

输出:

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.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。