版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
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();
}
}
}