The assignment states
“Write a program to print only even numbers between 6 and 16 using
events.”
while in the class we only use CL applications just having a button wouldnt work. So I thought about using an if than statement that would raise an event if CurrentNumber is even with mod 2 as current number is declared as 6
While CurrentNumber < 17
If CurrentNumber Mod 2 Then
RaiseEvent Even()
CurrentNumber = CurrentNumber + 1
Else
CurrentNumber = CurrentNumber + 1
End If
End While
But how would I handle the event to console.writeline(CurrentNumber) basically what I need to do is to make a program that prints even numbers using events how I was trying to solve the problems was to invoke in event if the number is even that shows the current number
I think you are on the right track. What if you were to build a class that only had one purpose–to count numbers and raise events when an even or odd number occurs? Let’s say this class is called
Counter.Next, what if your
Programclass had an instance of theCounterclass and had an event handler only for theEvenevent? The handler could perform aConsole.WriteLine()each time an even number occurs.