Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy can't my enum be found in another class?
    text
    copied!<p>When trying to access an <code>enum</code>, called Monsters, from another class, Visual Studio gives me the error "The type or namespace name 'Monsters' could not be found (are you missing a using directive or an assembly reference?)", despite having an associated <code>using</code> in my class.</p> <p>Here is my enum code:</p> <pre><code>namespace Zadify.Enums { public enum Monsters { Zombie, Skeleton, Mummy, Robot, Demon } } </code></pre> <p>And here is my class I need to access it from:</p> <pre><code>using System; using System.Xml.Serialization; using Zadify.Enums; namespace Zadify { [Serializable] public abstract class Goal { //Properties, Other methods public void AssignMonsterData(int rank) { var random = new Random(); var monsterTypeValues = Enum.GetValues(typeof (Monsters)); //Gives the error on "Monsters" here var monster = (Monsters) monsterTypeValues.GetValue(random.Next(rank - 1)); //Also gives the error on this "Monsters" //Do other stuff } </code></pre> <p>I later do a <code>switch</code> on <code>monster</code>, and it seems to be fine with every time I use <code>Monsters.Zombie</code>, <code>Monsters.Skeleton</code>, etc. I also have several other <code>enums</code> in <code>Zadify.Enums</code> that all work fine, and, in fact, I use the exact same code on them in this class.</p> <p>So far I have tried changing the enum's <code>namespace</code> and adding a <code>using</code> to that new <code>namespace</code>, copying <code>Monsters</code> into another file, cleaning the project, and rebuilding a hundred times. I'm using Visual Studio 2010 and writing a Mono for Android app, though there is no Android code in these classes.</p> <p>Visual Studio doesn't seem to have a problem until I build. Beforehand, intellisense works fine, if I take out the <code>using Zadify.Enums;</code> line, it asks if that's what I want to reference, and ctrl+clicking it brings me to the proper file.</p> <p>If there is any other code I should provide, let me know.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload