C# Struct, Handling Bool type with methods? -


i thought knew how handle structures, since have programmed in c years. however, have come across struct definition in c# program attempting understand. populated booleans , each instance of struct going cell in array (not shown here). expect override in line 3 used override method "tostring()" in base class.

public struct cell     {         public bool occupied;          public cell(bool occupied) { this.occupied = occupied; }          public override string tostring() { return occupied ? "x" : "."; }     } 

i understand first line above. believe confused use of methods in structures, assuming second , third lines in above struct definition methods. second line confusing me.

thank tom

the second line in struct constructor of struct (so yeah, it's method) takes boolean parameter , assigns value passed in "occupied" field.

the third line override of tostring method, inherited because it's built-in method of object class, superclass of every other object exists in c#. default, outputs fully-qualified class/struct name.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

json - Gson().fromJson(jsonResult, Myobject.class) return values in 0's -