C# Inheritance of same class twice -


let's i've such code

public class holded {     protected internal int holdedid = 0; }  public class inventory : holded {     public inventory() { }      public void changeholdedid()     {         this.holdedid = 100;     } }  public class equipment : holded {     public equipment() { }      public void writeholdedid()     {         console.writeline("holded id is: {0}!", this.holdedid);     } }  public class cargo : holded {     public cargo() { } } 

if i'd call changeholdedid , writeholdedid, console still output string "holded id is: 0!". want achieve have same base class (holded) in both of classes. if i'd change holdedid inventory, equipment's writeholdedid function output "holded id is: 100!". , regards!

@edit: more detailed: have game. each person character, owns equipment, inventory , cargo class. each class contains 20 slots "items". thing is, if try move item, ex. inventory, equipment, , there's such index of item, item "swapped" - goes holded, , may throw such holded item equipment, inventory or cargo. that's why i'm in need share such class between eq/inv/cargo.

a dictionary store person , holdedid might work

public class holded {     protected internal static dictionary<string, int> _personholdedids;     internal string _person;      public holded(string person)     {         _person = person;          if (_personholdedids == null)             _personholdedids = new dictionary<string, int>();          if (!_personholdedids.containskey(_person))             _personholdedids.add(_person, 0);     } }  public class inventory : holded {     public inventory(string person) : base(person) { }      public void changeholdedid()     {         _personholdedids[_person] = 100;     } }  public class equipment : holded {     public equipment(string person) : base(person) { }      public void writeholdedid()     {         console.writeline("holded id is: {0}!", _personholdedids[_person]);     } } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -