parent - generic why not?

How can use parentes with generic links
I talk about this constructions:

struct abc<tfrom>: tfrom
{...}

or

class abc<tfrom>: tfrom
{...}



Answer this question

parent - generic why not?

  • SONB

    You can specify a base for your type. If your base is object, then you'd have constructors, I would think.



  • TaddeR

    but i need constructions like

    public class aaa <tKey, tVal, tTVal>
                          :
    IConfig where tKey : int where tVal: int where tTVal: byte
    {...}

     

    public class aaa <tKey, tVal, tTVal>
                          :
    IConfig where tKey : Enum where tVal: Enum where tTVal: Enum
    {...}

    ___________________________________________

    without this logic i must do huge amount of code

    public class AAA <tKey, tVal, tTVal> : IConfig
    {

    private tKey _key;
    private tKey _key_new;
    private bool _key_changed = false;
    private tVal _val;
    private tVal _val_new;
    private bool _val_changed = false;
    private tTVal _tval;
    private tTVal _tval_new;
    private bool _tval_changed = false;
    private bool _dis;
    private bool _dis_changed = false;
    private bool _dis_new;

    public tKey Key
    {
    get { return _key_changed _key_new : _key; }
    set { _key_new = value; _key_changed = true; }
    }

    public tVal Value
    {
    get { return _val_changed _val_new : _val; }
    set { _val_new = value; _val_changed = true; }
    }

    public tTVal TypeValue
    {
    get { return _tval_changed _tval_new : _tval; }
    set { _tval_new = value; _val_changed = true; }
    }

    public bool Disabled
    {
    get { return _dis_changed _dis_new : _dis; }
    set { _dis_new = value; _dis_changed = true; }
    }

    public int Key_int
    {
    get { return Key.GetHashCode(); }
    }

    public int base_Key_int
    {
    get { return _key.GetHashCode(); }
    }

    public int Val_int
    {
    get { return Value.GetHashCode(); }
    }

    public int base_Val_int
    {
    get { return _val.GetHashCode(); }
    }

    public byte TypeValue_Byte
    {
    get { return (byte)(TypeValue.GetHashCode()); }
    }

    public byte base_TypeValue_Byte
    {
    get { return (byte)(_tval.GetHashCode()); }
    }

    public bool Changed
    {
    get { return _key_changed || _val_changed || _tval_changed || _dis_changed ; }
    }

    public AAA(tKey key_, tVal val_, tTVal tval_, bool disabled)
    {
    _key = key_;
    _val = val_;
    _tval = tval_;
    _dis = disabled;
    }

    }


  • Alain Martineau

    You can't, currently it's simply not supported (especially for structs which you never can specify a base type for).



  • MadBison

    how to use this conversions and why tjis is not work

    class aaa<tc>
    {
    public aaa()
     {
      int a = 0;
      tc b = (tc)a; // this not work
      tc c; // this not work
      // not exists any constructors like
      // tc b = new tc();
     }
    }

     


  • Phil Smith 99

    Actually:

    class aaa<tc> where tc : new()

    {

    public aaa()

    {

    int a = 0;

    // not exists any constructors like

    tc b = new tc();

    }

    }

    http://msdn2.microsoft.com/en-us/library/sd2w2ew5.aspx



  • RogerWS

    You can't call new on an int. Why would generics change that



  • parent - generic why not?