如何删除控制台应用程序中显示的文本,c#?

问题描述 投票:0回答:1

假设用户被要求提供手册。现在我们都知道手册既方便又广泛,例如我如何折叠/清除以便用户可以继续下一个活动?通过在按 M 后按 C,我希望用户立即跳转到下一个活动。

如何删除它?

这是代码:

static void Main(string[] args)
        {
            Console.WriteLine("Do you want to play the game?\nPress Y to continue\tPress M to view the rules\tEnter any key to exit. ");

            string iQuestion = Console.ReadLine();
            if (iQuestion.Equals("y", StringComparison.OrdinalIgnoreCase))
            {
                ProjectExecution();
                Console.WriteLine("\nWorld you like to try again?\nPress y to play again\tEnter any key to exit. ");
                string ask = Console.ReadLine();
                if (ask.Equals("y", StringComparison.OrdinalIgnoreCase))
                {
                    ProjectExecution();
                }
                else
                {
                    Console.WriteLine("Thank you for playing");
                }
                Console.Read();
            }
            else if (iQuestion.Equals("m", StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine("Hwewewe\nPress C to continue");\\This is just an example
                string mQuestion = Console.ReadLine();
                if (mQuestion.Equals("c", StringComparison.OrdinalIgnoreCase))
                {
                    Console.Clear();
                    ProjectExecution();
                    Console.Read();
                }
            }
            else
            {
                Environment.Exit(10);
            }
        }

我愿意接受另一种解决方案。

c# if-statement console console-application
1个回答
0
投票

我正在寻找相同的答案。我希望能够按 A 打开控制台行,但我不希望用户的文本出现在控制台中。

这是我的代码:

Console.BackgroundColor = ConsoleColor.Black;
static void PrintNewLine(int n)
{
    string newLines = new String('\n', n - 1);
    Console.WriteLine(newLines);
}
        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.WriteLine("TCO Blossom Acquisition Script");

        PrintNewLine(1);
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("Hello, Mr/Mrs/Ms _____?  My name is _____ and I’m calling on behalf of the Cleveland \r\nOrchestra. First and foremost I wanted to thank you for attending the Blossom Festival, \r\nI see you joined us for the (last concert in history) concert - I’d love to know how you \r\nenjoyed that performance! ");
        PrintNewLine(1);

        Console.ForegroundColor = ConsoleColor.Red;
        Console.WriteLine("(Build rapport with open ended questions - what was the highlight of the evening? How did they like their seats? etc)");
        PrintNewLine(1);
        Console.ForegroundColor = ConsoleColor.White;
        Console.WriteLine("Thank you for that, we always appreciate hearing from our audience members!  We’re \r\nexcited to have another great summer of music lined up this year - from classical \r\nfavorites like Rhapsody in Blue, to great films like Indiana Jones and Lord of the Rings, \r\nto special guest artists like Leslie Odom Jr of “Hamilton” fame, it’s going to be a great \r\nseason!  Many patrons aren’t aware of the benefits of subscribing - series holders save \r\nup to 30 % compared to individual tickets, and you get upgraded parking in our paved lot \r\nand reserved pavilion seats, so you know you can enjoy the concert rain or shine.");
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("*Let me ask you this, do you prefer symphonic masterworks, or music from film, Broadway and popular entertainers?*");

        PrintNewLine(1);
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.WriteLine("Interested in Classical? (Press A)");
        Console.WriteLine("Interested in Pops?      (Press B)");

while (true)
{
    PrintNewLine(1);
    Console.ForegroundColor = ConsoleColor.White;
    ConsoleKeyInfo result = Console.ReadKey();
    if ((result.KeyChar == 'A') || (result.KeyChar == 'a'))
    {
        Console.WriteLine("The classics series looks terrific, with highlights including Bela Fleck performing his \r\none-of-a-kind rendition of Rhapsody in Blue alongside the orchestra, music director \r\nFranz Welzer-Most conducting Tchaikovsky Symphony Number 5, and a terrific program \r\nfeaturing Christian Tetzlaff on Mozart Violin Concerto Number 5 alongside Beethoven \r\nSymphony Number 7.   Plenty of other great highlights as well - as a subscriber you get \r\nthe best seats at the best prices, with waived handling fees and free upgraded parking \r\nand ticket exchanges.  Plus you get the same seats for every concert.  For example, \r\nyou could get great seats for the entire series in the ______ section for $__ per person, \r\nhow does that sound?");
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("*If yes go to close. If no, pitch lower priced seating section or move to CYO.*");
        break;
    }
    if ((result.KeyChar == 'B') || (result.KeyChar == 'b'))
    {
        Console.WriteLine("The 4-concert Pops series features a pair of great film concerts with Indiana Jones: \r\nRaiders of the Lost Ark and Lord of the Rings: Return of the King.  It also includes a \r\nnight of Sinatra hits, and the “Cirque Goes Broadway” concert will pair classic show \r\ntunes with acrobatic feats.  Plenty of other great highlights as well - as a subscriber you \r\nget the best seats at the best prices, with waived handling fees and free upgraded \r\nparking and ticket exchanges.  Plus you get the same seats for every concert.  For \r\nexample, you could get great seats for the entire series in the ______ section for $__ \r\nper person, how does that sound?");
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("*If yes go to close. If no, pitch lower priced seating section or move to CYO.*");
        break;
    }
}

        PrintNewLine(1);
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.WriteLine("Move to Close   (Press A)");
        Console.WriteLine("Create Your Own (Press B)");

while (true)
{
    PrintNewLine(1);
    Console.ForegroundColor = ConsoleColor.White;
    ConsoleKeyInfo result = Console.ReadKey();
    if ((result.KeyChar == 'A') || (result.KeyChar == 'a'))
    {
        Console.WriteLine("Great, we’ll go ahead and set you up with ____ seat(s) in the _____ section for the \r\n_____ series.  That’s $___ per person which will bring the grand total to $____ - would \r\nyou like to put this on a mastercard, visa, AMEX or discover card?");
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("*Confirm card number and expiration, as well as address and email on file.*");
        break;
    }
    if ((result.KeyChar == 'B') || (result.KeyChar == 'b'))
    {
        Console.WriteLine("The choose your own series is a popular option, and it’s a great way to go if you’d like to \r\ncustomize your own series - just pick three or more concerts, and you can mix and \r\nmatch between classical, pops and special events like Leslie Odom Jr. and the Salute to \r\nAmerica.  You still get a 10% discount along with subscriber benefits like free parking \r\nand ticket exchanges.");
        Console.ForegroundColor = ConsoleColor.Yellow;
        Console.WriteLine("*Suggest concerts based on previous conversation and quote a few pricing options. If still no move to lawn pass booklet*");
        PrintNewLine(1);
        Console.ForegroundColor = ConsoleColor.Blue;
        Console.WriteLine("Quote Pricing     (Press A)");
        Console.WriteLine("Lawn Pass Booklet (Press B)");
        break;
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.