使用泛型类Stack<T>,实现字符串或数字的反序。
提示:泛型类Stack< >可以自己定义,也可以引入命名空间System.Collections,使用.NET提供的泛型类Stack< >
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stack<char> stack = new Stack<char>();
char []t={'d','s','w','g','c'};
for (int i = 0; i < 5; i++)
{
stack.Push(t[i]);
}
for (int i = 0; i < 5; i++)
{
Console.Write(stack.Pop());
}
Console.ReadKey();
}
}
}