這兩行有區別嗎?
byte[] b1 = Encoding.UTF8.GetBytes(s);
byte[] b2 = Encoding.GetEncoding("UTF-8").GetBytes(s);
uj5u.com熱心網友回復:
沒有區別啊,實作了相同的功能啊
uj5u.com熱心網友回復:
功能一樣,實作不一樣uj5u.com熱心網友回復:


//
// 摘要:
// Returns the encoding associated with the specified code page name.
//
// 引數:
// name:
// The code page name of the preferred encoding. Any value returned by the System.Text.Encoding.WebName
// property is valid. Possible values are listed in the Name column of the table
// that appears in the System.Text.Encoding class topic.
//
// 回傳結果:
// The encoding associated with the specified code page.
//
// 例外:
// T:System.ArgumentException:
// name is not a valid code page name. -or- The code page indicated by name is not
// supported by the underlying platform.
public static Encoding GetEncoding(string name)
{
Encoding ret=null;
switch(name)
{ //......
case "UTF-8":
ret=UTF8;
break;
//...
}
return ret;
}
只有運行效率上的微妙區別,可能在根據name回傳Encoding 上面,其他地方沒有區別,就是一個東西
uj5u.com熱心網友回復:
[quote=參考 3 樓 灬只有運行效率上的微妙區別,可能在根據name回傳Encoding 上面,其他地方沒有區別,就是一個東西
我用中文測驗了一下,回傳是一樣的。但是三個月前我做了一個專案,用的是斑馬列印機列印標簽,其中有中文,當時發現第一行列印不出來中文(出來的是亂碼),第二行可以列印出中文的。 當時時間緊,沒細究,現在有時間想拿出來研究一下單手頭沒設備了,所以貼到這兒來看大家有沒遇到過這種事情。
uj5u.com熱心網友回復:
我用中文測驗了一下,回傳是一樣的。但是三個月前我做了一個專案,用的是斑馬列印機列印標簽,其中有中文,當時發現第一行列印不出來中文(出來的是亂碼),第二行可以列印出中文的。 當時時間緊,沒細究,現在有時間想拿出來研究一下單手頭沒設備了,所以貼到這兒來看大家有沒遇到過這種事情。
您好,我又仔細查看了兩個方式得出的結果、生成的物件、用到的dll,發現他們都是一樣的。我的平臺是.netcore 3.1考慮是不是平臺的代碼問題?
uj5u.com熱心網友回復:
這是個歷史遺留問題,目前.net core正在全部統一化,結束目前版本亂七八糟的狀況。轉載請註明出處,本文鏈接:https://www.uj5u.com/net/252357.html
標籤:C#
