C# UTF-8返回错误的字符

C# UTF-8返回错误的字符,c#,.net,xamarin.forms,character-encoding,C#,.net,Xamarin.forms,Character Encoding,我一直在使用UTF-8编码将特定的十进制值转换为字符串,但返回的是“?”而不是“ü”。但在使用UTF-7编码时返回正确答案。请提供建议 System.Text.Encoding encoding; encoding = Encoding.UTF8; byte[] textbyte = new byte[] { Convert.ToByte(252) }; int byteLength = new byte[]

我一直在使用UTF-8编码将特定的十进制值转换为字符串,但返回的是“?”而不是“ü”。但在使用UTF-7编码时返回正确答案。请提供建议

        System.Text.Encoding encoding;
        encoding = Encoding.UTF8;            
        byte[] textbyte = new byte[] { Convert.ToByte(252) };
        int byteLength = new byte[] { Convert.ToByte(252) }.Length;
        string temp = encoding.GetString(textbyte, 0, byteLength);
预期结果:temp应具有“U”


实际结果:temp=“?”

这是您的工作示例

var encoding =new System.Text.UTF8Encoding(true,true);
var word = "ü";
byte[] bytes = encoding.GetBytes(word);
string temp = encoding.GetString(bytes);

您是否通过将“实际结果”打印到
控制台来检查它?如果是这样,您需要设置我将把这些结果字符添加到集合中。我将尝试将集合与搜索操作的用户定义字符相匹配。