mike
mike

Reputation: 21

C# XNA - 'Game' is a 'namespace' but is used like a 'type'

I don't understand how to fix this problem, what am I suppose to change 'Game' too?

 namespace Game {

    public class Help : Microsoft.Xna.Framework.GameComponent
    {
        public Help(Game game): base(game)
        {
           // TODO: Construct any child components here
        }

        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }
    } 
 }

Upvotes: 2

Views: 2385

Answers (5)

Neil Knight
Neil Knight

Reputation: 48537

If you are going to use your namespace of Game, then for everytime you want to use the Microsoft.Xna.Framework.Game class, you'll need to specify the full namespace Microsoft.Xna.Framework.

Upvotes: 2

Rhys
Rhys

Reputation: 11

I think your issue is the Game namespace as it is the same as the Game object type and the compiler can't differentiate them. Change the name of the namespace.

Upvotes: 1

Den
Den

Reputation: 1912

Rename your namespace 'Game' to something like MikesGame:

 namespace MikesGame {

    public class Help : Microsoft.Xna.Framework.GameComponent
    {
        public Help(Game game): base(game)
        {
           // TODO: Construct any child components here
        }

        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }
    } 
 }

Upvotes: 8

George Johnston
George Johnston

Reputation: 32258

Game is your namespace, just as the error suggests.

namespace Game {

Your attempting to pass in an object also called Game

public Help(Game game)

You either need to change your namespace to be something other than your object name, or fully qualify your object 'Game' if you have an object under another namespace called Game. e.g

public Help(AnotherNamespace.Game game)

Upvotes: 4

Kirk Woll
Kirk Woll

Reputation: 77536

You named your namespace "Game" which collides with the built in XNA type, Game. Change Game to Microsoft.Xna.Framework.Game or rename your namespace to something else.

Upvotes: 2

Related Questions