c# - Fetch a value of a property of an object in ArrayList -


I started a ArrayList for Windows Forms in C #. I am adding new objects with some properties of each object in , such as:

  ArrayList FormFields = new ArrayList (); CDDatabaseFieldDB = newCDDatabaseField (); Db.FieldName = FieldName; // fieldname, the input value received from the Windows Form Db.PageNo = PageNo; // page, description, button command area name is also received like DB. Description = description; Db.ButtonCommand = ButtonCommand; FormFields.Add (DB);  

Now when I want to check only FieldName of each object in ArrayList (assuming that there are many objects in the code> ArrayList ). How can I do this?

I tried:

 for  (int i = 0; i  

But this is causing the error (in the IDE). I'm new to C # programming, so can someone help me with this ??

Error: Error 21 'object' has no definition for 'field name' and no extension method 'fieldname' does not accept 'first argument' of type 'object' can be found (Do not you remember the Use Director or Assembly Reference?)

Array list holds objects It is not normal and is safe. That's why you need to reach your object to your property. Instead, consider using generic collections such as list & lt; T & gt; .

  varFormFields = new list & lt; CdatabaseField & gt; (); CDDatabaseFieldDB = newCDDatabaseField (); ... formfield.ed (db); Then you can see that all the properties will be visible because now the compiler knows the type of elements and allows you to access your type of members safely in a way. 


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -