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.
}
}
}
我如何获得输出?我已经写了评论以尝试理解...但是我没有得到控制台输出。我希望代码将其放入文件中,将所有字符串放入堆栈中,并将该堆栈中的每一行发送到reverseMe()函数,这是一个布尔值。布尔将查看字符串的正向还是反向,如果是,则返回true或false。尝试运行此代码时,我的控制台基本上是空的。我该怎么办?
嗯,从reverseMe()函数获取结果后,没有Console.WriteLine()可以进行任何实际输出。