《編寫高品質代碼:改善C#程式的157個建議》中關于勘誤的描述:
資源及勘誤
通常情況下,一個問題的解決方案往往不止一種,你可能會不同意本書中的一些觀點,甚至會強烈反對。沒有關系,你可以通過
[email protected] (E-mail)與我分享你的寶貴意見,同時也可以在 http://www.cnblogs.com/luminji下載下傳書中的源碼。我也經常在那裡發表部落格。當然,你一定也會在書中找到一些錯誤,我已經在部落格上放置了一篇勘誤表,我會在第一時間公布這些勘誤。
以下是勘誤部分:
1:44
原:
int[] iArr = { 0, 1, 2, 3, 4, 5, 6 };
ArrayList arrayListInt = ArrayList.Adapter(iArr);
arrayListInt.Add(7);
修改為:
int[] iArr = { 0, 1, 2, 3, 4, 5, 6 };
ArrayList arrayListInt = new ArrayList(iArr);
arrayListInt.Add(7);
2:P178
textBoxPage.Text = content;
if (textBoxPage.InvokeRequired)
textBoxPage.BeginInvoke(new Action(() =>
{
textBoxPage.Text = content;
}));
else
textBoxPage.Text = content;
3:P279
不支援中文加解密
public static string EncryptString(string input, string password)
{
using (MemoryStream memoryStream = new MemoryStream())
using (SymmetricAlgorithm algorithm = CreateRijndael(password, salt))
{
algorithm.IV = iv;
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, algorithm.CreateEncryptor(), CryptoStreamMode.Write))
{
byte[] bytes = System.Text.Encoding.UTF32.GetBytes(input);
cryptoStream.Write(bytes, 0, bytes.Length);
cryptoStream.Flush();
}
return Convert.ToBase64String(memoryStream.ToArray());
}
}
public static string DecryptString(string input, string password)
{
using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(input)))
using (SymmetricAlgorithm algorithm = CreateRijndael(password, salt))
{
algorithm.IV = iv;
using (CryptoStream cryptoStream = new CryptoStream(memoryStream, algorithm.CreateDecryptor(), CryptoStreamMode.Read))
{
StreamReader sr = new StreamReader(cryptoStream, System.Text.Encoding.UTF32);
return sr.ReadToEnd();
}
}
}
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIn5GcuQmMyUjNmJWYlRmMhdTNhBjMmRDN0IzYmJmMhFGZ5IjMfdWbp9CXt92Yu4GZjlGbh5SZslmZxl3Lc9CX6MHc0RHaiojIsJye.png)
本文基于
Creative Commons Attribution 2.5 China Mainland License釋出,歡迎轉載,演繹或用于商業目的,但是必須保留本文的署名
(包含連結)。如您有任何疑問或者授權方面的協商,請給我留言。