Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
School/C# - Beginner (Denis)/Lesson 73/lesson_73.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43 lines (34 sloc)
1.23 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace Collections | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Stack<int> numbers = new Stack<int>(); | |
numbers.Push(3); // в стеке 3 | |
numbers.Push(5); // в стеке 5, 3 | |
numbers.Push(8); // в стеке 8, 5, 3 | |
// так как вверху стека будет находиться число 8, то оно и извлекается | |
int stackElement = numbers.Pop(); // в стеке 5, 3 | |
Console.WriteLine(stackElement); | |
Stack<Person> persons = new Stack<Person>(); | |
persons.Push(new Person() { Name = "Tom" }); | |
persons.Push(new Person() { Name = "Bill" }); | |
persons.Push(new Person() { Name = "John" }); | |
foreach (Person p in persons) | |
{ | |
Console.WriteLine(p.Name); | |
} | |
// Первый элемент в стеке | |
Person person = persons.Pop(); // теперь в стеке Bill, Tom | |
Console.WriteLine(person.Name); | |
Console.ReadLine(); | |
} | |
} | |
class Person | |
{ | |
public string Name { get; set; } | |
} | |
} |