zoukankan      html  css  js  c++  java
  • 基本类型泛型(二)

    164泛型接口

    165泛型委托

    166泛型方法

        public sealed class program {
            
    public static void Swap<T>(ref T a, ref T b) {
                T temp;
                temp 
    = a;
                a 
    = b;
                b 
    = temp;
            }

            
    public static void CallingSwap() {
                Int32 n1 
    = 10, n2 = 20;
                Console.WriteLine(
    "n1={0},n2={1}", n1, n2);
                Swap
    <Int32>(ref n1, ref n2);
                Console.WriteLine(
    "n1={0},n2={1}", n1, n2);
                String s1 
    = "Hello", s2 = "World";
                Console.WriteLine(
    "s1={0},s2={1}", s1, s2);
                Swap
    <String>(ref s1, ref s2);
                Console.WriteLine(
    "s1={0},s2={1}", s1, s2);
                Console.ReadLine();
            }

            
    public static void Main() {
                CallingSwap();
            }

        }
    167泛型和其他成员
    C#中,属性、索引器、事件、操作符方法、构造器和总结器本身不能有类型参数。然而,他们能在一个泛型类型中定义,而且这些成员中的代码可以使用类型的类型参数。
    168可验证性和限制



  • 相关阅读:
    2020软件工程作业04(2.0)
    2020软件工程作业03
    软件工程作业02
    2020软件工程作业02
    2020软件工程作业01
    2020软件工程个人作业06——软件工程实践总结作业
    2020软件工程作业05
    2020软件工程作业00——问题清单
    2020软件工程作业04
    2020软件工程作业02
  • 原文地址:https://www.cnblogs.com/tenghoo/p/1211100.html
Copyright © 2011-2022 走看看