c# - How do I check if an instance class is equal to a variable inside the class? -


how check if instance class equal variable inside class?

public class chaintype {     public chaintype none;     public chaintype unknown;     public chaintype horizontal;     public chaintype vertical;     public chaintype centercross;     public chaintype lefttopcornercross;     public chaintype righttopcornercross;     public chaintype leftbottomcornercross;     public chaintype rightbottomcornercross; }  public class aclass{     chaintype chaintype = new chaintype();      somemethod(){         chaintype = getchaintype(); // sets chaintype.horizontal          if(chaintype == chaintype.horizontal){..} // getting error here object reference non-static class     } } 

the tip addresses enums, let's forget that.

there subtile difference between code , example. class name bullets, plural. should change class name chaintypes , should fine.

public class chaintypes {     public chaintype none;     public chaintype unknown;     public chaintype horizontal;     public chaintype vertical;     public chaintype centercross;     public chaintype lefttopcornercross;     public chaintype righttopcornercross;     public chaintype leftbottomcornercross;     public chaintype rightbottomcornercross; }  chaintypes types = new chaintypes(); chaintype chaintype = getchaintype();    if (chaintype == types.horizontal) { } 

i understand reasoning, can quite tricky in comparisons (the tip doesn't address usages of bullets. comparison done on references, have make chaintypes static , make sure return correct instance.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -