001_泛型编程

泛型结合

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp
{ 
//结点
    class Node
    {
        T data;
        Node Link;

        public Node(T data,Node link) {
            this.data = data;
            this.Link = link;
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp
{
    class exanple_02
    {
        static void Swap(ref T vall, ref T val2) {
            T temp;
            temp = vall;
            vall = val2;
            val2 = temp;
        }

        static void Main() {
            int num1 = 100;
            int num2 = 2000;
            Console.WriteLine("num1:"+num1);
            Console.WriteLine("num2:" + num2);
            Swap(ref num1,ref num2);
            Console.WriteLine("num1:" + num1);
            Console.WriteLine("num2:" + num2);


            Node node1 = new Node("Mike", null);
            Node node2 = new Node("zhangdan", node1);

        }

    }
}

运行结果:
num1:100
num2:2000
num1:2000
num2:100

你可能感兴趣的:(001_泛型编程)