Array of objects - modyfing object's fields C#

后端 未结 6 704
滥情空心
滥情空心 2021-01-29 06:59

I\'ve got such a problem. I\'m a beginner in C#. I have an object array (various classes) and in one place of application I want to modify fields like an age or name. Construct

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 07:14

    It's an array of objects and as the error message suggests, 'object' does not contain a definition for 'age'

    You need to declare your array with the type that has age field or property.And the you can modify it whatever you want. For example:

    class Person 
    {
        public string Name { get; set; }
    }
    

提交回复
热议问题