当前位置:知识问问>百科知识>c#代码示例

c#代码示例

2023-12-21 06:14:03 编辑:join 浏览量:570

c#代码示例

using System;   class Hello {   static void Main() {   Console.WriteLine("Hello, world");   Console.ReadLine();   }   } 这个是最简单的下面这个是链表public class Node{ private object Element; public Node Link; public Node() { Element = null; Link = null; } public Node(object theElement) { Element = theElement; Link = null; } public void AddNode(object theElement) { Link = new Node(theElement); } public void AddNode(Node n) { Link = n; } public override string ToString() { return Element.ToString(); }}public class LinkedList{ public Node header; private Node current; public LinkedList() { header = new Node("header"); current = header; } public void Add(Node n) { current.AddNode(n); current = current.Link; } public void Add(object obj) { current.AddNode(obj); current = current.Link; }}这个是堆栈using System;using System.Collections ;namespace 栈的进入和弹出{ ///

/// Class1 的摘要说明。 /// class Class1 { /// /// 应用程序的主入口点。 /// [STAThread] static void Main(string[] args) { Stack colorStack=new Stack(); colorStack.Push("red"); colorStack.Push("green"); colorStack.Push("blue"); colorStack.Push("yellow"携迹); colorStack.Push("orange"); Console.WriteLine ("栈中内容早仿包括"辩睁并); foreach(string color in colorStack){ Console.WriteLine(color); } while(colorStack.Count>0){ string color=(string)colorStack.Pop(); Console.WriteLine("弹出{0}",color); } Console.WriteLine("结束"); Console.ReadLine(); } }}

标签:示例

版权声明:文章由 知识问问 整理收集,来源于互联网或者用户投稿,如有侵权,请联系我们,我们会立即处理。如转载请保留本文链接:https://www.zhshwenwen.com/article/326785.html
热门文章