I am having trouble passing the return value from TheMethod() to Main and displaying the word if the if statement is passed as true.
I have thought of two ways of doing this, neither has worked but I think I am missing synatx.
- Using a return ?; non void method and then displaying the returned value.
- Using a void method and actually writing out(example below)
So yes I am new at this, however I have made so many iterations everything is blending together and I have forgot what I have tried. Any help on the syntax be great for either of these ways.
Basically I need it to iterate numbers
1,2,3,4 and depending on if the current iteration matches an expression in the if statements it will display a word.
Example:
if (3 = i)
{
Console.WriteLine("Word");
}
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Proj5
{
class Program
{
int i = 0;
static void Main(int i)
{
for (i = 0; i < 101; i++)
{
Console.WriteLine("test");
}
}
string TheMethod(int i)
{
string f = "Word1";
string b = "Word2";
if (i == 3)
{
return f;
}
if (i == 5)
{
return b;
}
if (0 == (i % 3))
{
return f;
}
if (0 == i % 5)
{
return b;
}
else
{
return b;
}
}
}
}
Note: You don’t need if i == 5 and a separate one for i % 5 == 0. % is “mod” which means the remainder after the division, so 5 / 5 = 1, there is no remainder so 5 mod 5 = 0…
Here is a rough guide/fix for you attempt at FizzBuzz:
However there are cleaner solutions:
Or, if you prefer LINQ-y Lambas: