0
var maxHeight = draw._shapes.Aggregate((agg, next) =>next.height > agg.height ? next : agg); if (draw._shapes.Count == 0) trackBar_Size.Maximum = 484; else { foreach (float heights in maxHeight) { if (heights < 412) { trackBar_Size.Maximum = 484; } else if (heights > 412) { trackBar_Size.Maximum = 415; } } } 

Error 3 foreach statement cannot operate on variables of type 'sCreator.Shape' because 'sCreator.Shape' does not contain a public definition for 'GetEnumerator'

I got this error on the var maxHeight statement. So how do I fix this error and use the LINQ result as a float value?

1

2 Answers 2

5

That's because Aggregate method returned single value (from what I can see, the greatest value in _shapes).

Simply, try writing maxHeight.GetEnumerator() to see, that compiler would complain. In order to use foreach loop you need to have collection (which have iterator).

Or, try writing maxHeight.GetType() (or maxHeight.ToString()) to inspect, what it really is.

Or just inspect the variable in debug mode, setting breakpoints in appropriate places.

Sign up to request clarification or add additional context in comments.

Comments

1
var maxHeight = draw._shapes.Aggregate((agg, next) => next.height > agg.height ? next : agg); if (maxHeight.height > 412) { trackBar_Size.Maximum = 412; } else if (maxHeight.height < 412) { trackBar_Size.Maximum = 484; } 

This code will get your desired Height as a float value.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.