ambiguous/conflicting constructors in generic class

前端 未结 5 1064
小鲜肉
小鲜肉 2021-01-07 01:54

I\'ve got a generic class:

public class BaseFieldValue
{
    public BaseFieldValue()
    {
        //...
    }

    public BaseFieldValue(string val         


        
5条回答
  •  无人及你
    2021-01-07 02:42

    You could do the following:

    public class BaseFieldValue
    {
        public struct Special
        {
            internal string m_value;
            public Special(string value)
            {
                m_value = value;
            }
        }
    
        public BaseFieldValue()
        {
            //...
        }
    
        public BaseFieldValue(Special value)
        {
            //...
        }
    
        public BaseFieldValue(T value)
        {
            //...
        }
    }
    

    ... or, you could add an extra ignored boolean parameter to your special constructor, just to disambiguate it.

提交回复
热议问题