Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. A namespace does not directly contain.......

A namespace does not directly contain.......

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Skanless
    wrote on last edited by
    #1

    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?!?!?!

    L 1 Reply Last reply
    0
    • S Skanless

      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?!?!?!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • L 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

        S Offline
        S Offline
        Skanless
        wrote on last edited by
        #3

        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?!?!?!

        C 1 Reply Last reply
        0
        • S Skanless

          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?!?!?!

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          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

          S 1 Reply Last reply
          0
          • C Colin Angus Mackay

            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

            S Offline
            S Offline
            Skanless
            wrote on last edited by
            #5

            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?!?!?!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups