常用成员:
/* 属性 */ Count //只读 Length //同 Count, 但可读写 /* 方法 */ And() //与 Get() //取值 Not() //取反 Or() //或 Set() //赋值 SetAll() //全部设定为指定值 Xor() //异或
练习:
//(items)[]、Get()、Set() protected void Button1_Click(object sender, EventArgs e) { BitArray bits = new BitArray(new bool[3] { true, false, true }); bool b1 = bits[0]; //True bool b2 = bits[1]; //False //bool b1 = bits.Get(0); //bool b2 = bits.Get(1); bits[0] = false; bits[1] = true; //bits.Set(0, false); //bits.Set(1, true); bool b11 = bits[0]; //False bool b22 = bits[1]; //True TextBox1.Text = string.Concat(b1, "\n", b2, "\n", b11, "\n", b22); } //SetAll() 及遍历 protected void Button2_Click(object sender, EventArgs e) { BitArray bits = new BitArray(5); string str1 = ""; foreach (bool b in bits) { str1 += b.ToString() + " "; //False False False False False } bits.SetAll(true); string str2 = ""; foreach (bool b in bits) { str2 += b.ToString() + " "; //True True True True True } TextBox1.Text = str1 + "\n" + str2; } //Count、Length protected void Button3_Click(object sender, EventArgs e) { BitArray bits = new BitArray(5); int n1 = bits.Count; //5 bits.Length = 3; int n2 = bits.Count; //3 TextBox1.Text = string.Concat(n1, "\n", n2); } //Not() protected void Button4_Click(object sender, EventArgs e) { BitArray bits = new BitArray(new bool[4] { true, false, true, false }); bits.Not(); // False,True, False,True TextBox1.Text = string.Format("{0},{1},{2},{3}", bits[0], bits[1], bits[2], bits[3]); } //And() protected void Button5_Click(object sender, EventArgs e) { BitArray bits1 = new BitArray(new bool[4] { true, false, true, false }); BitArray bits2 = new BitArray(new bool[4] { true, true, false, false }); bits1.And(bits2); // True, False, False, False TextBox1.Text = string.Format("{0},{1},{2},{3}", bits1[0], bits1[1], bits1[2], bits1[3]); } //Or() protected void Button6_Click(object sender, EventArgs e) { BitArray bits1 = new BitArray(new bool[4] { true, false, true, false }); BitArray bits2 = new BitArray(new bool[4] { true, true, false, false }); bits1.Or(bits2); // True, True, True, False TextBox1.Text = string.Format("{0},{1},{2},{3}", bits1[0], bits1[1], bits1[2], bits1[3]); } //Xor() protected void Button7_Click(object sender, EventArgs e) { BitArray bits1 = new BitArray(new bool[4] { true, false, true, false }); BitArray bits2 = new BitArray(new bool[4] { true, true, false, false }); bits1.Xor(bits2); // False,True, True, False TextBox1.Text = string.Format("{0},{1},{2},{3}", bits1[0], bits1[1], bits1[2], bits1[3]); } //其它建立方法 protected void Button8_Click(object sender, EventArgs e) { //对象包含 3 个 true BitArray bits1 = new BitArray(3, true); //以 byte[] 为参数时, 将把其每个 byte 的 8 个位分别映射为一个元素 BitArray bits2 = new BitArray(new byte[3] { byte.MaxValue, byte.MinValue, byte.MaxValue }); //以 int[] 为参数时, 将把其每个 int 的 32 个位分别映射为一个元素 BitArray bits3 = new BitArray(new int[3] { int.MaxValue, int.MinValue, int.MaxValue }); int n1 = bits1.Length; //3 int n2 = bits2.Length; //24 int n3 = bits3.Length; //96 string s1, s2, s3; s1 = s2 = s3 = ""; foreach (bool b in bits1) { s1 = string.Concat(s1, Convert.ToByte(b)); } //111 foreach (bool b in bits2) { s2 = string.Concat(s2, Convert.ToByte(b)); } //11111111 //00000000 //11111111 foreach (bool b in bits3) { s3 = string.Concat(s3, Convert.ToByte(b)); } //11111111111111111111111111111110 //00000000000000000000000000000001 //11111111111111111111111111111110 TextBox1.Text = string.Concat(n1, "\n", n2, "\n", n3, "\n", s1, "\n", s2, "\n", s3); }
1、新建网站(或者asp.netWeb应用程序)2、创建一个类。继承System.Web.UI.Page,重写InitializeCulture()方法。类名:BasePage3、InitializeCulture()这样实现:String…
1、SQL语句分类1.1、分类方法及类型1.2、数据定义语言1.3、数据操纵语言1.4、其它语句2、动态SQL理论2.1、动态SQL的用途2.2、动态SQL的语法2.3、绑定变量3、动态SQL实战3.1、封装执行DML的通用存储过程3.2、…
简介在C#中,Dictionary提供快速的基于兼职的元素查找。当你有很多元素的时候可以使用它。它包含在System.Collections.Generic名空间中。在使用前,你必须声明它的键类型和值类型。详细说明必须包含名空间System…
就像WebApi接口可以对入参进行验证,避免用户传入非法的或者不符合我们预期的参数一样,选项也可以对配置源的内容进行验证,避免配置中的值与选项类中的属性不对应或者不满足预期,毕竟大部分配置都是通过字符串的方式,验证是很有必要的。1.注解…
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Con…
普通的邮件,用System.Net.Mail类或System.Web.Mail类处理即可,但是ExchangeServer环境下,这两个类起不了作用-------至少目前我看到的情况如此.整个过程如下:1.先添加COM引用"Microsof…
第一步:定义一个类:SysHandlerErrorAttribute继承HandleErrorAttribute重写OnException方法usingDw.Util;usingSystem;usingSystem.Collections.…
提供了针对可扩展的提供程序模型的基实现。命名空间:System.Configuration.Provider程序集:System.Configuration(在System.Configuration.dll中)C#publicabstra…