C# Program to Clear All Elements From Stack

You are currently viewing C# Program to Clear All Elements From Stack

C# program to clear all elements from stack

using System;
using System.Collections;

namespace ConsoleApplication1
{
    
    class Program
    {
        static void Main()
        {
            Stack S = new Stack(5);

            S.Push(10);
            S.Push(20);
            S.Push(30);
            S.Push(40);

            S.Clear();

            Console.WriteLine("Now stack is empty");
            

        }
    }
}

output

Now stack is empty

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply