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 enum
s, 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 bullet
s. comparison done on references, have make chaintypes
static , make sure return correct instance.
Comments
Post a Comment