Home [C# 筆記] 分析下面程式碼,a、b 的值是多少?
Post
Cancel

[C# 筆記] 分析下面程式碼,a、b 的值是多少?

1
2
3
4
5
6
string strTmp = "a1某某某";
int a = System.Text.Encoding.Default.GetBytes(strTmp).Length;
int b = strTmp.Length;

//a = 11(1+1+3*3)
//b = 5

分析:在UTF-8編碼下,每個中文字元通常佔用3個位元組,而每個英文字元和數字佔用1個位元組。

UTF-8編碼一個中文字佔3 bytes,而BIG5編碼一個中文字佔2 bytes

C# .NET面试系列一:基础语法

This post is licensed under CC BY 4.0 by the author.

[C# 筆記] 在 .net 中,Assembly 的意思是?

[C# 筆記] Strings = new String(“xyz”); 建立了幾個 String Object?