Like Tree1Likes
  • 1 Post By Momerath

using namespace ....

This is a discussion on using namespace .... within the C# Programming forums, part of the General Programming Boards category; Hey, so I was given a gift of visual studio 2010 Game Studio 4.0 and a yr membership with Xbox ...

  1. #1
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407

    Question using namespace ....

    Hey, so I was given a gift of visual studio 2010 Game Studio 4.0 and a yr membership with Xbox indie (for submitting games), and I sighed as I was really happy to dev for my 360 for my first time ever I am also having to leant a new language a new compiler and a new framework. It all seems pretty straightforward and the documentation for game studio is better than I expected, but I was in the habit of breaking most of my programs into sperate headers to keep things organized but with c# it seems to be a little different. I am trying to peice this together and I am sure after only a few days i may seem rwtarded, but is the using namespace randomnamspace. The new way to do #includes? Like if I wanted to break a game down into different files could I just add new .cs to the project define a namespace in it then just put using thatnamepsace at the top of my main page? What are common pitfalls or probelms I should avoid with learning this new method?

    Thanks in advance for any info.. also I will be buying a book on it soon if anyone has any suggestions (I don't want a beginner book with a lot of "fluff")

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Namespaces are entirely different than #includes. Adding "using <namespace>;" to a file just prevents you from having to use the FQN of types that reside in that namespace. For instance, if you didn't have "using System.Collections.Generic;", you'd have to type:
    Code:
    System.Collections.Generic.List<int> listOfIntegers = new System.Collections.Generic.List<int>();
    Instead of...
    Code:
    List<int> listOfIntegers = new List<int>();
    So not including the "using" doesn't prevent you from using types in that namespace, it just provides a shortcut way of identifying types in your code.

    You're definitely still free to break your code up into different .cs files, but generally the namespace will be the same and you'll break your program out into different classes. For instance, you're going to add a GameObject class, you'd right-click your project, select Add -> New Class, type in GameObject.cs and then the IDE will create the new file along with some standard usings, a namespace structured after the project/file heirarchy, and a stub for the class itself.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Ok so all the "include" stuff is now managed by the ide or the language then?

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    41
    Yes, sort of. By default Visual Studio includes references to the most common set of objects, but you may have to add references (right click on references in solution explorer) to some of the DLLs. Once you add a reference to a DLL, any object in that DLL is available (public object, that is) for you to use.

    As for books, I'd go with the O'Reilly books, specifically C# 4.0 in a Nutshell, 4th Edition..-..O'Reilly Media
    Last edited by Momerath; 11-17-2012 at 07:56 PM.
    Lesshardtofind likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Friend of namespace or of namespace function?
    By Programmer_P in forum C++ Programming
    Replies: 18
    Last Post: 03-13-2011, 06:46 PM
  2. using namespace std;
    By spank in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2006, 05:28 AM
  3. std namespace
    By bigSteve in forum C++ Programming
    Replies: 8
    Last Post: 01-20-2004, 01:56 AM
  4. namespace help
    By dodge_tomahawk in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2004, 05:18 PM
  5. namespace std
    By strobe9 in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 08:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21