51.在程序里面调用web.config里面的SQL server连接字段
<appSettings>
<add key="wjcking"
value="SQL 连接字段"/>
</appSettings>
调用:
string sql_connection_string=System.Configuration.ConfigurationSettings.AppSettings["wjcking"];
52.
string currentLine = ...;
string[] items = currentLine.Split(new string[] { ", " }, StringSplitOptions.None);
53.
ComBox中输入字符超长时,Box长度随着字符长度而变化。
private void findWidthForDropDown(ComboBox comboBox)
{
bool isDatabound = comboBox.DataSource != null && comboBox.DisplayMember != null && comboBox.DisplayMember != "";
int widestWidth = comboBox.DropDownWidth;
string valueToMeasure;
int currentWidth;
using (Graphics g = comboBox.CreateGraphics())
{
for (int i = 0; i < comboBox.Items.Count; i++)
{
if (isDatabound)
valueToMeasure = (string)((DataRowView)comboBox.Items[i])[comboBox.DisplayMember];
else
valueToMeasure = comboBox.Items[i].ToString();
currentWidth = (int)g.MeasureString(valueToMeasure, comboBox.Font).Width;
if (currentWidth > widestWidth) { widestWidth = currentWidth; }
}
}
comboBox.DropDownWidth = widestWidth;
}
54.数组的定义
int[] array = new int[10]; // 整型一维数组
for (int i = 0; i < array.Length; i++)
array[i] = i;
or int[] test = new int[] { 1, 3, 4 };
int[,] array2 = new int[5,10]; // 整型二维数组
array2[1,2] = 5;
55.用正则表达式匹配
using System.Text.RegularExpressions;
Regex regex = new System.Text.RegularExpressions.Regex(正则);
regex.IsMatch(要匹配的字符串);