天天看點

C#中Encoding.Unicode與Encoding.UTF8的差別

unicode隻是給這世界上每個字元規定了一個統一的二進制編号,并沒有規定程式該如何去存儲和解析。 可以說utf-8是unicode實作方式之一...

在c#中,system.text.encoding.unicode與system.text.encoding.utf8分别是2種編碼方式。如果utf-8是unicode的一種實作方式,那c#中為什麼将encoding.unicode作為與utf8并列的一種編碼方式呢?

windows handles so-called "unicode" strings as utf-16 strings, while most unixes default to utf-8 these days. 

原來windows預設的unicode實作是utf-16,是以c#中encoding.unicode就是utf-16。

system.text.encoding.unicode的注釋也證明了這一點:

C#中Encoding.Unicode與Encoding.UTF8的差別
C#中Encoding.Unicode與Encoding.UTF8的差別

c#中,encoding.unicode = utf-16 。

繼續閱讀