C#练习3

using System;
class Test
{
  static void F(params int[]args)
  {
      Console.WriteLine("# of argument:{0}",args.Length);
      for(int i=0;i<args.Length;i++)
          Console.WriteLine("\targs[{0}]={1}",i,args[i]);
  }
  static void Main()
  {
      F();//没有参数,默认传递的是 new int[0],但不是null
      F(1);
      F(1, 2);
      F(1, 2, 3);
      F(new int[] { 1, 2, 3, 4 });
  }
}

 

using System;
public class Stack
{
    private Node first = null;
    public bool Empty
    {
        get
        {
            return (first == null);
        }
    }
    public object Pop()
    {
        if (first == null)
            throw new Exception("Can't Pop from an empty Stack.");
        else
        {
            object temp = first.Value;
            first = first.Next;
            return temp;
        }
    }
    public void push(object o)
    {
        first = new Node(o, first);
    }
    class Node
    {
        public Node Next;
        public object Value;
        public Node(object value) : this(value, null) { }
        public Node(object value,Node next)
        {
            Next = next;
            Value = value;
        }
    }
}

 

posted @ 2014-03-04 02:09  zhangyongjian  阅读(113)  评论(0编辑  收藏  举报