本文介绍了Console.Write的问题(@"")......请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我是C#的初学者。我想创建一个基本程序,我们在其中重复添加数字。我很成功但我也希望通过不显示当前答案是xxx这一行来使其变得更简单每次我输入一个数字。我希望文本只保留在一个地方,只有当我们得到一个新的答案时才能改变这个数字。这就是为什么我写了一行Console.Write(@),但它没有似乎工作。请告诉我,如果我做错了,请告诉我正确的代码。Hi,I'm a beginner in C#.I wanted to create a basic program in which we add numbers repeatedly.I was successful but I also wanted to make it more simple by not displaying the line "The current answer is xxx" every time I enter a number.I wanted the text to stay in just one place and only the number to change when we have a new answer.That's why I wrote the line Console.Write(@"") but it doesn't seem to work.Please tell me if I'm doing something wrong and please tell me the correct code.namespace Tutorial1{ class Program { static void Main(string[] args) { int answer, current; string currenttranslated; answer = 0; do { currenttranslated = Console.ReadLine(); current = int.Parse(currenttranslated); answer = current + answer; Console.Write(@"The current answer is {0}",answer); Console.WriteLine(); } while (0 == 0); } }}推荐答案class Program { static void Main(string[] args) { int answer, current; string currenttranslated; answer = 0; do { Console.Write("Enter new number: "); currenttranslated = Console.ReadLine(); Console.Clear(); current = int.Parse(currenttranslated); answer = current + answer; Console.Write(@"The current answer is {0}", answer); Console.WriteLine(); } while (true); } } 还要考虑退出程序的可能性(没有无限循环),也许如果输入无效数字?您可以查看 int.TryParse 并退出循环 快乐编码 JohannesAlso think about a possibillity to exit the program (no endless loop), maybe if a non valid number is entered? You could check with int.TryParse and exit the loophappy codingJohannes 这篇关于Console.Write的问题(@"")......请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-01 15:00