【发布时间】:2020-07-01 00:41:37
【问题描述】:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace Palindrome
{
class Program
{
static void Main(string[] args)
{
string filePath = @"C:\Users\Me\Desktop\Palindromes\palindromes.txt";
//This gets the file we need
var meStack = new Stack<string>();
//this creates the stack
foreach (var item in File.ReadLines(filePath))
{
meStack.Push(item.ToUpper());
}
//for every item in the file, push onto the stack and make it upper case
while (meStack.TryPop(out string Line))
{
reverseMe(Line);
}
//While every line in the stack is popped out, every line goes to the fucntion reverseMe
static bool reverseMe(string Line)
{
return
Line == Line.Reverse();
}
//return true if line is the same as the line backwards or false if its not.
}
}
}
如何获得输出? 我已经编写了 cmets 来尝试理解......但我没有得到控制台输出。我希望代码接收文件,将所有字符串放入堆栈,并将堆栈中的每一行发送到 reverseMe() 函数,这是一个布尔值。 bool 将查看字符串是否向前和向后相同,如果是,它将返回 true 或 false。基本上,当我尝试运行此代码时,我的控制台是空的。我该怎么办?
【问题讨论】:
-
程序应该做什么?我看不到任何输出。您可能想要添加
Console.Write或Console.WriteLine以在控制台上写入内容 -
这是一个调试问题,请在提问前先学习如何使用调试器,然后当你无法理解某些内容时,将这些信息带到问题中,你期望发生什么,正在发生什么,它发生了什么。
-
static bool IsPalindrome(string input) { return input.SequenceEqual(input.Reverse()); }应该可以工作,因为您正在尝试将IEnumerables与Reverse进行比较
标签: c# output comments palindrome