A namespace does not directly contain.......
-
CAn someone please help to decipher why I am getting the follwoing message: "C:\Class Test\Class Test 2\OrigClass.cs(26): A namespace does not directly contain members such as fields or methods" Please see the code below. It looks fine to me. using System; namespace ClassTest2 { /// /// Summary description for Class1. /// class Point { public Point() { Console.WriteLine("This is the default constructor"); } public Point(int x, int y ) { Console.WriteLine("x:{0}, y:{1}", x, y); } } static void Entrance() { Point Origin = new Point(); Point bottomRight = new Point (600, 800); } }
Skan If you knew it would not compile why didn't you tell me?!?!?!
-
CAn someone please help to decipher why I am getting the follwoing message: "C:\Class Test\Class Test 2\OrigClass.cs(26): A namespace does not directly contain members such as fields or methods" Please see the code below. It looks fine to me. using System; namespace ClassTest2 { /// /// Summary description for Class1. /// class Point { public Point() { Console.WriteLine("This is the default constructor"); } public Point(int x, int y ) { Console.WriteLine("x:{0}, y:{1}", x, y); } } static void Entrance() { Point Origin = new Point(); Point bottomRight = new Point (600, 800); } }
Skan If you knew it would not compile why didn't you tell me?!?!?!
On an indented view, it would be more obvious, but it seems your Entrance method is not inside any class, and that's what gets rejected. In C# all code and data must reside inside a class, a namespace can only contain types (such as class, struct, enum). If your coming from C or C++ this may be a surprise. Now when you create a project in Visual Studio, you will get a class for free (named Form1 or something, depends on the kind of project). Also I expect the compiler to tell you exactly which line it did not like. If all of this is mysterious, I suggest you start reading a book on C# and have a look into one of the beginners articles on CodeProject... :)
Luc Pattyn
-
On an indented view, it would be more obvious, but it seems your Entrance method is not inside any class, and that's what gets rejected. In C# all code and data must reside inside a class, a namespace can only contain types (such as class, struct, enum). If your coming from C or C++ this may be a surprise. Now when you create a project in Visual Studio, you will get a class for free (named Form1 or something, depends on the kind of project). Also I expect the compiler to tell you exactly which line it did not like. If all of this is mysterious, I suggest you start reading a book on C# and have a look into one of the beginners articles on CodeProject... :)
Luc Pattyn
Thanks for your prompt response. I do have a C++ background thus thinking by using Void it should be covered but evidently not so. I tried using additional brackets but to no avail. I receive the following error: Program 'C:\Class Test\Class Test 2\obj\Debug\ClassTest2.exe' does not have an entry point defined As to your suggestion about using a C# book I have started doing that and ironically this code was one copied directly out of the book. Thanks -- modified at 19:20 Tuesday 30th January, 2007
Skan If you knew it would not compile why didn't you tell me?!?!?!
-
Thanks for your prompt response. I do have a C++ background thus thinking by using Void it should be covered but evidently not so. I tried using additional brackets but to no avail. I receive the following error: Program 'C:\Class Test\Class Test 2\obj\Debug\ClassTest2.exe' does not have an entry point defined As to your suggestion about using a C# book I have started doing that and ironically this code was one copied directly out of the book. Thanks -- modified at 19:20 Tuesday 30th January, 2007
Skan If you knew it would not compile why didn't you tell me?!?!?!
Skanless wrote:
ironically this code was one copied directly out of the book.
If this was a Microsoft Press book then I'm not surprised. Many code examples in MS Press books have had syntax errors in them. There is obviously not enough QA done at the proof reading stage.
Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos
-
Skanless wrote:
ironically this code was one copied directly out of the book.
If this was a Microsoft Press book then I'm not surprised. Many code examples in MS Press books have had syntax errors in them. There is obviously not enough QA done at the proof reading stage.
Upcoming events: * Glasgow Geek Dinner (5th March) * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos
Your guess was right...................it is a microsoft press book and I have to admit that I had found several error in there ASP.net book too but I di not know C# enough to identify the errors. Wow...............I guess there are a lot of people who use these book just to find out how erroneous they are.
Skan If you knew it would not compile why didn't you tell me?!?!?!