Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please Help! Never worked with IEnumerator before and it is giving me ulcers!

I am using the following 'using' statements:

using System;
using System.IO;
using System.Linq;
using System.Media;
using System.Windows.Forms;
using System.Collections.Generic;

the statement

IEnumerable<oscillator> oscillators in this.Controls.OfType<oscillator>();

gives me an error. What am I doing wrong?

(Obviously, oscillator is defined elsewhere in my code.)

What I have tried:

First, maybe I should explain that I am copying this code from a (horribly out of focus) video so it is almost impossible to see what the guy is doing. He does explain, but not sufficient for me to figure out what is going on.

Searched the internet for solutions but I could not find any website that gave me an answer that would apply to my situation.
Posted
Updated 31-Jul-22 1:21am
Comments
George Swan 31-Jul-22 8:08am    
Have you tried searching the articles section of this site? There is an excellent selection available

We can't tell, without a lot more code than that - and if the source is out of focus you could have done anything! And just saying "gives me an error" doesn't help at all without knowing what error, and where in the code! Remember, we can't compile that in isolation to even begin working out what the problem might be - and we have no idea what you expected it to do either!

I strongly suggest that if the video is out of focus and the explanation is inadequate, then you scrap it and start looking for something more professional, or ask the author for explanation - most YouTube development videos are poor quality because the author has no idea how to make a video, no idea how to teach, and more often than not no idea how to code either. Monetization is the key to YouTube riches, not ability or quality.

If you have to stick with this video (and it's probably a bad idea) then break up the code:
var x = Controls.OfType<oscillator>();
var y in x ...
and look at what type x and y are actually going to be in VS - that should give you a starting point to work out what is going on.
 
Share this answer
 
Quote:
I am copying this code from a (horribly out of focus) video
Why, when there is a perfectly clear explanation at IEnumerable Interface (System.Collections) | Microsoft Docs[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900