Show/Hide Toolbars

XSharp

foreach statement cannot operate on variables of type 'type1' because 'type2' does not contain a public definition for 'identifier'

 

To iterate through a collection using the foreach statement, the collection must meet the following requirements:

 

•It must be an interface, class or struct.

•It must include a public GetEnumerator method that returns a type.

•The return type must contain a public property named Current, and a public method named MoveNext.

•For more information, see How to: Access a Collection Class with foreach.

Example

 

In this sample, foreach is not able to iterate through the collection because there is no publicGetEnumerator method in MyCollection.

 

The following sample generates XS1579.

 

 

// XS1579.prg