Micah Weech
Micah Weech

Reputation: 31

C# programming error - Expression denotes a `type', where a `variable', `value' or `method group' was expected

Here is my code. I'm stuck with this recurring error and am at a loss for what to do next. Any guidance on what direction to look in would be great as I am learning how to code. The error message is listed below.

Error CS0119: Expression denotes a 'type', where a 'variable', 'value' or 'method group' was expected

using System;
using System.Collections.Generic;
using System.Data.Odbc;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace Kata
{
    public static class PascalsTriangle
    {
        new public static void Main()
        {
            int no_row, c = 1, blk, i, j;

            Console.Write("\n\n");
            Console.Write("Display the Pascal's triangle:\n");
            Console.Write("--------------------------------");
            Console.Write("\n\n");

            Console.Write("Input number of rows: ");
            no_row = Convert.ToInt32(Console.ReadLine());

            for (i = 0; i < no_row; i++)
            {
                for (blk = 1; blk <= no_row - i; blk++) ;

                Console.Write("  ");

                for (j = 0; j <= i; j++)
                {
                    if (j == 0 || i == 0)
                        c = 1;
                    else
                        c = c * (i - j + 1) / j;

                    Console.Write("{0}   ", c);
                }

                Console.Write("\n");
            }
        }
    }
}

Upvotes: 3

Views: 986

Answers (1)

John Wu
John Wu

Reputation: 52210

Remove this line:

using static System.Console;

This line takes advantage of a syntax that isn't introduced until c#6 (see this article). You would only need to include that line if you wish to use WriteLine or ReadLine without specifying the class that it belongs to. Since you are not, you can take it out.

Or you could compile against c# 6 or Roslyn, where your code compiles fine-- see this Fiddle.

I took the liberty of removing the extra ; (see AlphaDelta's note) and I can get it to render a triangle. Output:

Display the Pascal's triangle:
--------------------------------

Input number of rows: 5
          1   
        1   1   
      1   2   1   
    1   3   3   1   
  1   4   6   4   1

Upvotes: 6

Related Questions