ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
C# 中文字符比较 or C#汉字比较 or  C# 中文字符串比较 or C#中文名字比较 原文链接:https://blog.csdn.net/u013628121/article/details/53782932 ``` /// <summary> /// 类扩展 /// </summary> public static class StringEx {     /// <summary>     /// 比较中文字符是否相等     /// </summary>     /// <param name="name1"></param>     /// <param name="name2"></param>     /// <returns></returns>     public static bool ChinesComPare(this string name1,string name2)     {         name1 = name1.Replace(" ", "");//去除掉名字直接的空格         name2 = name2.Replace(" ", "");//去除掉名字直接的空格         byte[] utf81 = Encoding.UTF8.GetBytes(name1);         byte[] utf82 = Encoding.UTF8.GetBytes(name2);         bool equal = utf81.IsEqual(utf82);         return equal;     }     /// <summary>     /// 比较2个字节数组是否相等     /// </summary>     /// <param name="src"></param>     /// <param name="dis"></param>     /// <returns></returns>     public static bool IsEqual(this byte[] src, byte[] dis)     {         bool isEq = false;         if (src.Length != dis.Length)         {             isEq = false;         }         else         {             isEq = true;             for (int i = 0; i < src.Length; i++)             {                 if (src[i] != dis[i])                 {                     isEq = false;                     break;                 }             }         }         return isEq;     } }         string n1 = "杨光";         string n2 = "杨 光 ";         if (n1.ChinesComPare(n2))         {             //true         } ```