docs icon indicating copy to clipboard operation
docs copied to clipboard

Program.cs(351,17): error CS0116: A namespace cannot directly contain…

Open DebasisPaul opened this issue 2 years ago • 1 comments

… members such as field s, methods or statements ; Whats The Possible Solution Here.

using System;

namespace ConsoleApp6 { static void Main(string[] args) { int sum = 0; for (int number = 1; number < 21; number++) { if (number % 3 == 0) { sum = sum + number; } } Console.WriteLine($"The sum is {sum}"); } }

// In the video tutorial there is no problem in this code. But when i do the same code the error come out.

Summary

Describe your changes here.

Fixes #Issue_Number (if available)

DebasisPaul avatar Aug 05 '22 13:08 DebasisPaul

This might just be a concern with not using top-level statements.

IEvangelist avatar Aug 05 '22 14:08 IEvangelist

Hi @DebasisPaul

I think what's missing is the class. Here's the correct version:

namespace ConsoleApp6
{
    public static class Program
    {
        static void Main(string[] args)
        {
        int sum = 0;
        for (int number = 1; number < 21; number++)
        {
            if (number % 3 == 0)
            {
                sum = sum + number;
            }
        }
        Console.WriteLine($"The sum is {sum}");}
    }
}

I'll close this, as the PR is an unrelated whitespace change. I hope this info helps you finish the tutorial.

BillWagner avatar Aug 11 '22 15:08 BillWagner