StringBuilder , Hashtable
StringBuilder 对于操作字符串来说真的有它的一些优点,有时候还是很方便的。namespace在System.Text下。举个小例子大家一看就明白。
StringBuilder sb = new StringBuilder("aa"); //sb = "aa"
string strTest = sb.ToString();
sb.Append("dd");
strTest = sb.ToString(); //strTest = "aadd"
sb.Append(10);
strTest = sb.ToString(); //strTest = "aadd10"
/// <summary>
/// 根据任意字段删除
/// </summary>
/// <param name="FieldName">字段名</param>
/// <param name="FieldValue">字段值</param>
/// <param name="flag">为真则精确删除,为假为模糊删除</param>
public void DeleteOne(string FieldName,object FieldValue,bool flag)
{
StringBuilder sb = new StringBuilder();
string sql;
if(FieldValue is int)
{
sb.AppendFormat("delete from {0} where {1} = {2}",this.TableName,FieldName,FieldValue.ToString());
}
else if(FieldValue is string)
{
if(flag)
sb.AppendFormat("delete from {0} where {1} = '{2}'",this.TableName,FieldName,FieldValue.ToString());
else
sb.AppendFormat("delete from {0} where {1} like '%{2}%'",this.TableName,FieldName,FieldValue.ToString());
}
else//删除全部
sb.AppendFormat("delete from {0}",this.TableName);
sql = sb.ToString();
}
说到Hashtable 也真是满好用的,至少可以形成键,值 的双存储,而不用你另外做工作了,而且都是object类型,随便你存储了。namespace : System.Collections
Hashtable ht = new Hashtable();//哈希表用来存放ID/Bool键值对
for (int i = 0; i < 10; i++)
{
ht.Add(object key, object value);
}
IDictionaryEnumerator ide;
ide= al.GetEnumerator();
while(ide.MoveNext())
{
id = (object)ide.Key; //object 可以换做你加入时的任何类型
seted = (object)ide.Value; //
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
说到Hashtable 也真是满好用的,至少可以形成键,值 的双存储,而不用你另外做工作了,而且都是object类型,随便你存储了。namespace : System.Collections
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)