Cannot implicitly convert type 'T' to 'Int'

后端 未结 6 1813
轻奢々
轻奢々 2020-12-16 14:38

When trying to call this function in my code i get the error in the title. Also Operator \'+=\' cannot be applied to the operands of type \'int\' and \'T\'

p         


        
6条回答
  •  鱼传尺愫
    2020-12-16 15:05

    I had a very similar problem. It is not exactly the problem asked here, but it could be a start point:

        private T GetXValue(XElement xElem, string name)
        {
            try
            {
                object o = xElem.Element(name).Value;
                return (T)Convert.ChangeType(o, typeof(T));
            }
            catch 
            {
                return (T)Activator.CreateInstance(typeof(T), null);
            }
        }
    

提交回复
热议问题