I’m new to C#, so forgive this noobish question. I’m playing with a simple XNA game demo. I have a struct that I want to be available to several classes. It is defined as follows:
PhotonType.cs
using System;
namespace ShipDemo
{
public struct PhotonType {
public Color tint;
}
}
In another file in the same folder/namespace, Ship.cs, I reference this struct:
namespace ShipDemo {
public class Ship {
//...
private PhotonType photonType;
//...
public Ship(float x, float y, float ang, Boolean correctSound, PhotonType photonType) {
//...
}
}
This gives me compilation errors on both references to PhotonType.
Error 1 The type or namespace name
‘PhotonType’ could not be found (are
you missing a using directive or an
assembly
reference?)
What am I doing wrong here?
////
Also, the C# documentation says
It is an error to initialize an
instance field in a struct.
But what if I want to provide default values?
I’m using Visual Studio Ultimate 2010 Beta.
Are the 2 files in the same Project? If your namespace is split up between 2 projects, you need to reference the project containing PhotonType in the other project.
I fthis is the case, I would question the design as usually we don’t split the same namespace in more than one assembly.