C#第四章上机练习2

C#第四章上机练习2

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

namespace 第四章上机练习2
{
    class Class1
    {
        public void showName()
        {
            Console.WriteLine("请输入您的姓名:");
            string strUserName = Console.ReadLine();
            Console.WriteLine("格式化处理后你的姓名:");
            string name = FormateName(strUserName);
            Console.WriteLine(name);
        }
        public string FormateName(string strUserName)
        {
            string[] strNameItrm = strUserName.Split(new char[] { ' ' });
            for (int i=0;i<strNameItrm.Length ;i++)
            {
                strNameItrm [i]=strNameItrm [i].Substring (0,1).ToUpper ()
                    +strNameItrm [i].Substring (1).ToUpper ();
            }
            string name =string.Join("",strNameItrm );
            return name ;
        }
    }
}

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

namespace 第四章上机练习2
{
    class Program
    {
        static void Main(string[] args)
        {
            Class1 ok = new Class1();
            ok.showName ();
            Console.ReadLine();
        }
    }
}

你可能感兴趣的:(C#)