为什么输出字母个数少一个啊?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    namespace ConsoleApplication_foreach
    {
        class Program
        {
            static void Main(string[] args)
            {
                string[] arry1 = new string[] { "I am", "a student", "study in the xh", "Conputer skill", "shool !" };
                int ZM = 0, KG = 0, ZF = 0;
                string s = "";
                foreach (string i in arry1)
                {
                    s += i; //将所有字符串连接并赋给字符串变量变量s。
                    //Console.WriteLine(s);
                   // Console.WriteLine(s.Length);
                }
                char[] arry2 = s.ToCharArray();//将字符串变量s转换成字符数组。
                foreach (char i in arry2)
                {
                    //Console.WriteLine(i);
    
                    ZF = arry2.Length;//字符的个数。
                    if (char.IsLetter(i))
                    {
                        ZM++; //字母的个数
                    }
                    else if (char.IsWhiteSpace(i))
                    {
                        KG++;  //空格的个数
                    }
                }
                    Console.WriteLine("所有字符的个数为{0}", ZF);//输出 49
                    Console.WriteLine("字母的个数为{0}", ZM);//输出 41  为什么不是42 ? 啊要疯了!
                    Console.WriteLine("空格的个数为{0}", KG);//输出 7
                    Console.Read();

        }

    }
}
阅读 3.3k
1 个回答

“!”感叹号要是看见你问这个问题得多伤心

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进