Ghorea Tsarvawa

Ghorea Tsarvawa

  • NA
  • 5
  • 1.5k

Cannot put member fields in namespaces, but they aren't

Feb 8 2014 3:53 AM
In my IDE, SharpDevelop v4.3.1, I receive the following error: "A namespace cannot directly contain members such as fields or methods (CS0116)."
The problem is that I do not have anything directly in a namespace.  The code below is the entire file and there is nothing else that can trigger the error.  The _ are just space holders because the forum doesn't like spaces.  What's even weirder is that it all works until it reaches Console.WriteLine() for the first time, as if the program is fine with Console.ReadLine() but not the other.

using System;

namespace Problem
{
__public class ClassA
__{
____public static void Main(string[] args)
____{
______ClassB.MethodA();
____}
__}
__
__public class ClassB
__{
____public static String str_a = "";
____public static String str_b = "";
____public static String str_c = "";
____public static bool bool_a = false;
____public static int[] int_a;
____
____public static void MethodA()
____{
______while (str_a == "" || str_a == null)
______{
________String str_a2 = Console.ReadLine();
________if (str_a2 == "" || str_a2 == null)
________{
________}
________else
________{
__________str_a = str_a2;
________}
______}
______
______while (str_c == "")
______{
________String str_c2 = Console.ReadLine();
________if (str_c2 == "" || str_c2 == null)
________{
________}
________else
________{
__________str_c = str_c2;
________}
______}
______
______while (bool_a == false)
______{
________Console.WriteLine("");
________public static int[] int_b;
________
________for (int i = 0; i < 6; i += 1)
________{
__________int_a[i] = 0;
________}
________bool_a = true;
______}
____}
__}
}

Answers (4)