c# - How to implement instance numbering? -


i don't know if title clear trying implement this:

public class effect {     public int internalid ...      public void resetname() ... } 

when resetname called, reset name of object to:

"effect " + someindex; 

so if have 5 instances of effect, renamed to:

"effect 1" "effect 2" "effect 3" ... 

so have method (resetnames) in manager/container type calls resetname each instance. , right have pass integer resetname while keeping counter myself inside resetnames. feels not clean , prevents me calling resetname myself outside manager class, valid.

how better/cleaner?

as internalid, it's id stores creation order everything. can't rely on these, because numbers large, 32000, etc.

edit: container resetnames code:

int count = 1; var effects = this.effects.orderby ( n => n.internalid ); foreach ( effect effect in effects ) {     effect.resetname ( count );     ++count; } 

have manager class handles naming. handle creation of child class, , embed reference itself. can call resetname() on child class, , have it's manager handle whatever logic needs done.

i'm not sure want results in various situations, following of help:

public class effect { {   private effectmanager _manager;   public string name {get;set;}    public effect(effectmanager manager) {     _manager = manager;   }    public void resetname() {     name = _manager.getnextname();   } }  public class effectmanager {   private list<effect> effects;   private int currentindex;   public effect createeffect() {     var e = new effect(this);     effects.add(e);   }    public string getnextname() {     return "effect " + currentindex++;   }    public void resetallnames() {     currentindex = 0;     foreach(var effect in effects) {       effect.name = getnextname();     }   } } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -