例如想将字符串“123456”赋给SecureString类型,可采用以下两种方法:(以下两种方法其实是一样的,只是一个没有用循环,一个用了循环)
1、SecureString password=new SecureString();
password.AppendChar('1');
password.AppendChar('2');
password.AppendChar('3');
password.AppendChar('4');
password.AppendChar('5');
password.AppendChar('6');
2、string strPassWord="123456";
char[] pChar=strPassWord.ToCharArray();
SecureString password=new SecureString();
foreach(char c in pChar)
{
password.AppendChar(c);
}
然后直接用password就可以了。