zoukankan      html  css  js  c++  java
  • C#泛型代理、泛型接口、泛型类型、泛型方法

    //http://www.cnblogs.com/JeffreySun/archive/2012/11/14/2770211.html
    //http://www.baqima.com/a/2628.html
    //http://www.cnblogs.com/yangqi/archive/2010/07/16/1778767.html
    //http://www.cnblogs.com/TianFang/p/3928172.html
    
    using System;
    using System.Threading;
    
    namespace Demo
    {
        public delegate T3 MyDelegate<T1, T2, T3> (T1 t1, T2 t2);
    
        interface MyInteface<T1, T2, T3>
        {
            T1 DoIT (T2 t2, T3 t3);
        }
    
    
        public class MyClass<T1, T2, T3> : MyInteface<T1, T2, T3>
        {
            public T1 DoIT (T2 t2, T3 t3)
            { 
                //throw new NotImplementedException ();
                T1 t1=default(T1);
                return t1;
            }
        }
    
        //primary constructor
        //public class User(string name, string password){}
    
        public class Demo
        {
            private static readonly float KaiFaQu_WuYeFei = 18.8f;
    
            public static float Pay (int PeopleCount, string Family)
            {
                float result = PeopleCount * KaiFaQu_WuYeFei;
                Console.WriteLine ($"Faimily:{Family} Pay fee {result:c}");
                return result;
            }
    
            static void Swap<T> (ref T t1, ref T t2)
            {
                T temp = t1;
                t1 = t2;
                t2 = temp;
            }
    
    
            public static void Main ()
            {
                String str1 = "abc", str2 = "efg"; 
                Swap<String> (ref str1, ref str2);
                Console.WriteLine ($"{str1}	{str2}");
    
                MyDelegate<Int32, String,float> FamXu = new MyDelegate<Int32, String,float> (Pay); 
                MyDelegate<Int32, string,float> FamLiujie = Demo.Pay;
    
                float MoneyXu = FamXu (4, "XU Minghui");
                float MoenyLiu = FamLiujie (3, "LiuJie");
    
                //
                MyClass<float,int,string> my =new MyClass<float,int,string>();
                float MoneyMu = my.DoIT (3, "Mu Jingyu");
                Console.ReadKey ();
            }
        }
    }
  • 相关阅读:
    Android实现摇晃手机的监听
    C#实现目录复制
    c# splitter控件使用简介
    一行代码实现java list去重
    安卓最简通讯录操作样例
    java.lang.ClassNotFoundException错误原因汇总
    在Visual Studio 2013中编译libssh2项目
    VS2013中C++创建DLL导出class类
    c#发送邮件样例
    Linux服务器挂死案例分析
  • 原文地址:https://www.cnblogs.com/flaaash/p/5361875.html
Copyright © 2011-2022 走看看