Это видео недоступно.
Сожалеем об этом.
📚Stacks in C# explained, how to use them and when to use them
HTML-код
- Опубликовано: 12 окт 2021
- Welcome, this is a C# tutorial about stacks
🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg
Read the article and get the code: tutorials.eu/s...
In this video you will learn about stacks in C#, how and when to use them and what is the difference with queues
In this tutorial we will see how to implement a stack in C#
Stacks are usually used when data reversal is needed or is a solution to our problems as we will see in the example at the end of
Defining a stack in C#
we can define a stack in the same way we define any collection
here we will define a stack that takes integer numbers
Adding and viewing data in a Stack
We can add elements to our stack using the method Push()
add elements to our stack
as we run the application we will see that every time we use the Peek() method we will get the last value we Pushed into our stack
Removing Elements from a Stack
To remove elements from our stack we will use the method Pop()
which will remove the element on top of the stack and will return it at the same time
of course we don't want to use Pop() on an empty stack since this will throw and error so first we need to check the Count property of the stack which will return how many elements are in our stack
Removing Elements from a Stack
To remove elements from our stack we will use the method Pop()
which will remove the element on top of the stack and will return it at the same time
of course we don't want to use Pop() on an empty stack since this will throw and error so first we need to check the Count property of the stack which will return how many elements are in our stack
Example Reversing an array
one of the many applications of stacks is data reversal in the following example we will use a stack to reverse an array
The solution is simple
1. we will go through the elements of the array from start to end and we will push each element into a stack
2.After that we will pop and print every element in the stack until it's empty
stack, push c#, c# stack size, c# stack to list, c# stack pop, c# stack peek, c# stack vs list
tutorialsEU offers you free video tutorials about programming and development for complete beginners up to experienced programmers.
This includes C#, Unity, Python, Android, Kotlin, Machine Learning, etc.
Stay tuned and subscribe to tutorialsEU: goo.gl/rBFh3x
🚀 C# Progress Academy - Become a job-ready C# and Angular web developer to land your dream developer role: bit.ly/45vbPUg
A good teacher makes it sound easy, like you do here - thanks mate!
Is it possible to stack without an array/list? Show me how to create your Push, Pop, etc method.
Thanks you teacher. =)
You are welcome : )
int[] numbers = new int[] { 1, 69, 666, 23, 85, 74, 23, 96, 51 };
Stack stack = new Stack();
numbers = numbers.OrderBy(x => x).ToArray();
foreach (int number in numbers)
{
stack.Push(number);
}
foreach (var test in stack)
{
Console.WriteLine(test);
}
Great teacher, please translate your courses into Spanish or Portuguese if possible. I am Brazilian and I have some of your courses, they are excellent courses. A big hug here from Brazil. Peace and light!
Hey! We will definitely look into it :)