如何使用 arcobject 更改字段长度

How do change field length with arcobject

我想用下面的代码更改 sdegeodatabse 中的一些字符串字段。代码是 运行 没有任何问题。但在 运行 之后,将长度 return 归档为默认长度。我错过了什么?

static void writetablecode(IDataset dataset)
        {
            ITable table = dataset as ITable;

            IFieldsEdit fields = table.Fields as IFieldsEdit;
            for (int i = 0; i < fields.FieldCount; i++)
            {
                IFieldEdit field = fields.Field[i] as IFieldEdit;
                if (field.Type==esriFieldType.esriFieldTypeString & field.Length<30 )
                {
                    field.Length_2  = 30;
                }

            }
        }

无法编辑字段的长度,实现此目的的唯一方法是创建一个新字段,将数据复制到新字段。 http://support.esri.com/de/knowledgebase/techarticles/detail/42783

IFieldEdit 无论如何都不应该用于更改现有字段。来自 API 参考:

The IFieldEdit interface is used when creating new fields. You should not use it to modify fields, for that purpose use IClassSchemaEdit. In general, when modifying fields, the restrictions that apply in ArcCatalog also apply in ArcObjects; for example, you cannot change the name or type of a field.