c#问题怎么重复了

来源:百度知道 编辑:UC知道 时间:2024/06/19 17:45:19
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个字符串,个单词以空格分隔:");
string word = Console.ReadLine();//转换钱的字符串
GetString(ref word);//转换后的字符串
Console.WriteLine("按Pascal规则转化后的名称是:{0}",word);

Console.ReadLine();
}
private static void GetString(ref string word)
{
string tempWord;
string[] splitStrings = word.Split(' ');
for (int i = 0; i < splitStrings.Length; i++)
{
tempWord = splitStrings[i].Substring(0,1).ToUpper();
word = word + tempWord;
tempWord = splitStrings[i].Substring(1).ToLower();
wo

你要问的是什么?

请用以下代码替换:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
Console.WriteLine("请输入一个字符串,个单词以空格分隔:");
string word = Console.ReadLine();//转换钱的字符串
// ref 是引用类型,也就是说,用了ref以后,GetString()方法出来的word的值将替换掉方法前定义的word
GetString(word);//转换后的字符串
Console.WriteLine("按Pascal规则转化后的名称是:{0}",word);

Console.ReadLine();
}
private static void GetString(ref string word)
{
string tempWord;
string[] splitStrings = word.Split(' ');
for (int i = 0; i < splitStrings.Length; i++)
{
tempWord = splitStrings[i].Substring(0,1).ToUpper();
word = word + tempWord;
tempWord = splitStrings[i].Substring(1).ToLower();
word = word + tempWord;
}

//string joinString = string.Join("",spli