3

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");
            }
        }
    }
}
6
  • 2
    Just a tip, on the line for (blk = 1; blk <= no_row - i; blk++); that ; at the end will make sure that the next line is not part of the for statement, you'll need to remove that semicolon for the Console.Write(" "); to be apart of the for statement. Commented Oct 30, 2017 at 23:42
  • 1
    What line causes the error? That is usually really important info to include. Also, did you intend to write using static System.Console;? Commented Oct 30, 2017 at 23:45
  • Error is on that using static line. But AlphaDelta has outlined another important issue with this code. I would recommend using the { } curly brackets wherever possible. Commented Oct 30, 2017 at 23:47
  • @Rufus: do not remove actual code when editing a question. The error very well could be (and in this case is!) related to the code you remove, and your edit to the question is such cases renders the question unanswerable, incomprehensible, or both. Commented Oct 30, 2017 at 23:54
  • @PeterDuniho thanks, I actually just noticed that I removed the namespaceand using part and was putting it back when I saw you already did - thanks! Commented Oct 30, 2017 at 23:55

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.