add field to an IFeatureClass

Discussion created by geo_hecsanmol on Jul 2, 2012
Latest reply on Jul 24, 2012 by Neil
Hello, I am beginning to programs with and c# and of arcobjects do not belong almost anything.

Can someone say to me how add a field (text or integer) to an object of type IFeatureClass and as put then information in him??

I try it this way:

' Create a new fields collection.
            Dim fields As IFields = New FieldsClass()

            ' Cast to IFieldsEdit to modify the properties of the fields collection.
            Dim fieldsEdit As IFieldsEdit = CType(fields, IFieldsEdit)

            ' Set the number of fields the collection will contain.
            fieldsEdit.FieldCount_2 = 1

            ' Create the text field.
            Dim textField As IField = New FieldClass()
            Dim textFieldEdit As IFieldEdit = CType(textField, IFieldEdit)
            textFieldEdit.Length_2 = 30 ' Only string fields require that you set the length.
            textFieldEdit.Name_2 = "Edificio_Afectado"
            textFieldEdit.Type_2 = esriFieldType.esriFieldTypeString

            ' Add the new field to the fields collection.
            fieldsEdit.Field_2(0) = textField

' Here it gives mistake

' Add the field.

Thank you very much. Bye.