登陆 | 注册
你现在的位置:我的论坛 >> 微软新技术 >> 创建泛型的实例
创建泛型的实例
大狗熊

class A
    {
        public String d = null;
        public A()
        {
            d = "demo";
        }
    }

    class B
    {
        public String d = null;
        public B()
        {
            d = "demo";
        }
    }

    class C
    {
        public T makeT<T>() where T : new()
        {
            return new T();
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            C c = new C();
            Console.Write(c.makeT<B>().d);
           
        }
    }

楼主 创建:08-05-08 16:22:36 更新:08-06-14 22:41:23
发表回复

1/1(共1页)
大狗熊

//按引用传递Float
    public class CFloat
    {
        private float m_value = 0F;

        public float Value
        {
            get
            {
                return this.m_value;
            }
        }

        public CFloat()
        {
           
        }

        public CFloat(float value)
        {
            this.m_value = value;
        }

        public override string ToString()
        {
            return Value.ToString();
        }

        public static implicit operator float(CFloat cf)
        {
            return cf.Value;
        }

        public static explicit operator int(CFloat cf)
        {
            return (int)cf.Value;
        }

        public static CFloat operator +(CFloat c, float x)
        {
            c.m_value += x;
            return c;
        }
    }

1楼 创建:08-06-19 12:57:18 更新:08-06-19 13:07:30
发表回复
1 共1条
Copyright (C) 2004-2008, All Rights Reserved