-2

The below code is giving me error "Cannot assign to 'writeline' because it is a 'method group;" at every Console.Writeline statement. I am trying to find out why but I could not find anything to point me in right direction. Any help appreciated.

{
class FizzBuzz
{
    static void Main(string[] args)
    {
          for (int i = 1; i <= 100; i++)
              if ((i % 3 == 0) && (i % 5 == 0))
        {
        Console.WriteLine = "Fizzbuzz" ;
        }
              else if (i % 3 == 0)
              { 
              Console.WriteLine =  "Fizz";
              }
              else 
                  (i % 5 == 0)
        {
        Console.WriteLine = "Buzz";
        }
                        System.Console.ReadLine();
        }

}

}
HereToLearn_
  • 1,150
  • 4
  • 26
  • 47
  • 2
    `WriteLine` is a method not a variable or property, so you should use it like this `Console.WriteLine("Fizz")` – chomba Apr 09 '15 at 01:33
  • Hi @chomba I made the change you suggested. duh! but I am still getting the same error even after the change is put in. Also for statement else (i % 5 == 0) I am getting an error which says "Error 3 Only assignment, call, increment, decrement, and new object expressions can be used as a statement" – HereToLearn_ Apr 09 '15 at 01:39
  • There's an `else if` statement missing in your code `else if (i % 5 == 0)`. Please read some basic tutorials on c# before posting questions :) – chomba Apr 09 '15 at 01:49
  • Nevermind I got it. I was not seeing it.. I still had equal to sign after console.writeline.. silly mistake. and I was able to get ride of the other (i%5==0) error by using else if instead of if. – HereToLearn_ Apr 09 '15 at 01:50

1 Answers1

1

You need to set the string in parenthesis:

Console.WriteLine("This string goes to console.");

You tried to assign the method with a value, that is not possible. That works only with properties and fields.

Koopakiller
  • 2,838
  • 3
  • 32
  • 47