[英]string array upper and lower letters change C#
I need to print an array of strings line by line, where the first line has to be with uppercase letters, the second line with lowercase letters and thats how it goes until the end of the array (I get the array from a text file); 我需要逐行打印一个字符串数组,其中第一行必须使用大写字母,第二行必须使用小写字母,这就是直到数组结尾的方式(我从文本文件中获取数组) ;
When I try to use to use " chars[i].ToUpper
" I get the error 当我尝试使用“
chars[i].ToUpper
”时出现错误
"Error 1 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement C:\\Users\\Yonatan\\Documents\\Visual Studio 2013\\Projects\\Clab2\\Clab2\\ex3.cs 21 17 Clab2"
“错误1只有赋值,调用,递增,递减,等待和新对象表达式可以用作语句C:\\ Users \\ Yonatan \\ Documents \\ Visual Studio 2013 \\ Projects \\ Clab2 \\ Clab2 \\ ex3.cs 21 17 Clab2”
this is my code: 这是我的代码:
static void Main(string[] args)
{
string fileContent = File.ReadAllText("FreeText.txt");
string[] chars = fileContent.Split(new char[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
for(int I =0;i<chars.Length;i++)
{
if (i % 2 != 0)
chars[i].ToUpper;
}
}
the first line has to be with uppercase letters,the second line with lowercase letters
第一行必须使用大写字母,第二行必须使用小写字母
You have to overwrite the string in the array with the upper/lower-case strings: 您必须使用大写/小写字符串覆盖数组中的字符串:
if (i % 2 != 0)
chars[i] = chars[i].ToUpper();
else
chars[i] = chars[i].ToLower();
Replace 更换
chars[i].ToUpper();
to 至
chars[i] = chars[i].ToUpper();
ToUpper is a method, not a property. ToUpper是一种方法,而不是属性。 Also you have to reassign it, because ToUpper will return a new string.
另外,您还必须重新分配它,因为ToUpper将返回一个新字符串。
Try with this: 试试这个:
for (int i = 0; i < chars.Length; i++)
{
if (i % 2 != 0)
{
chars[i] = chars[i].ToUpper();
}
else
{
chars[i] = chars[i].ToLower();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.