SoFunction
Updated on 2025-04-04

Solution to (T) failure in C#

() "Invalid"? ? ?

     public void RemoveCustomMaterialInfo(MaterialInfo info)
        {
            if (m_MaterialList == null)
            {
                return;
            }

            if (m_MaterialList.Contain(info))
            {
                m_MaterialList.Remove(info);
                ($"delete :info: {}, {}, {},{}, left : {this.m_MaterialList.Count}");

                //Storage local                //var content = (this.m_MaterialList);
                var content = (GetMaterialInfoListBySerial("Customize"));
                (MaterialCustomConfigPath, content);
            }
        }

Get used to this, but accidentally stepped on a pit

(T t) t must be a reference in the original list to be valid. If info is created by you new, I'm sorry, it's useless, including Remove.

===》Disposal method:

       private bool Contain(MaterialInfo materialInfo)
        {
            if (this.m_MaterialList == null)
            {
                return false;
            }

            return m_MaterialList.Exists(
                info => () && ()
                                                                && ()
                                                                && ());
        }

This is all about this article about (T) failure in C#. For more relevant C# (T) failure content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!