【发布时间】:2020-11-19 09:17:21
【问题描述】:
我想通过 C# 编写一个程序,将给定字符串的每个单词的首字母大写。 它给了我一个错误:不能将属性或索引器分配给-它是只读的。 当我使用 ToUpper 时,错误是:“ToUpper 在当前上下文中不存在”。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace Csharp_Training
{
class Program
{
static string Captilaize(string Text)
{
for (int i = 0; i < Text.Length; i++)
{
if (i == 0)
{
Text[i] = ToUpper(Text[i]);//here when i used Text[i] giv me error: Property or indexer cannot be assigned to -- it is read only
}
else if (Text[i - 1] == ' ')
{
Text[i] = ToUpper(Text[i]);// ToUpper Does not exist in current context
}
}
return Text;
}
static void Main(string[] args)
{
Console.Write(Captilaize("cpp string exercises"));
}
}
}
【问题讨论】:
标签: c#