To use it from an ArrayList
, you must first apply it to the appropriate type. ArrayList
saves elements as an object
.
var item = (marker)markers[0];
However, assuming you are using a C # version released since 2005 (that is, C # 2.0+), you would be better off using List<T>
, where T
is the type of object. It is strongly typed, can only store elements of type T
and does not require operations to complete operations.
List<marker> markers = new List<marker>(); markers.Add(new marker());
List<T>
is available in the System.Collections.Generic namespace.
Unrelated, since you're new to C #, learn the language conventions that almost all C # developers adhere to. A few basic ones: class names, properties, methods - PascalCased, private members, parameters, local variables - camelCased, and class data is displayed as properties, and not as public fields.
public class Marker { public string WhatsHappening { get; set; }
source share