WPF 几个知识点

来源:互联网 发布:医学论文数据库 编辑:程序博客网 时间:2024/05/20 00:12

1,主程序关闭

 Environment.Exit(0);

2, 可序列化的类

[Serializable]

public class  classname

{

}

3,序列化与反序列化

FileStream fs = new FileStream("data.bin", FileMode.OpenOrCreate);

BinaryFormatter bf = new BinaryFormatter();

bf.Serialize(fs, clssname);   //序列化数据入文件

  Dictionary<string, clssname> clssnames= bf.Deserialize(fs) as Dictionary<string, clssname>;  //反序列化出数据


4,字符串与ASCII  转换

 char[] charBuf = str.ToArray();    // 将字符串转换为字符数组
            ASCIIEncoding charToASCII = new ASCIIEncoding();


            byte[] TxdBuf = new byte[charBuf.Length];    // 定义缓冲区;
            TxdBuf = charToASCII.GetBytes(charBuf);    // 转换为各字符对应的ASCII

//ASCII 变为字符串

int ascII = int.Parse(sstr);
                    str += Encoding.ASCII.GetString(new byte[] { (byte)ascII });

5,禁止关闭窗体

        private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
        }