rohit pol

rohit pol

  • NA
  • 6
  • 35k

parent class member elements are not accessible in child class

Apr 14 2012 11:05 AM

Hello,

Sorry for dumb question.
My Dictionary member 'data' of Parent class has elements but showing zero elements when I access in child class. Is there any issue in declaration in parent class.

*****Child Class************
namespace Auto
{
    public class ChildClass : BaseClass
    {
        public ChildClass() { }
        public ChildClass(string prefix)
        {  new BaseClass(prefix);  }

        public void test()
        {
            string dta = data["hello.user"]; //data has 0 elements here. But when I debug it has elements in parent class. 
                                                      //Why elements are not getting here from parent class. 
                                                      //Is there any issues with declaration of data in parent here.
        }
    }
}

*****Base Class************
namespace Auto
{
    public class BaseClass
    {
        protected Dictionary<string, string> data = new Dictionary<string, string>();
        public BaseClass() { }
        public BaseClass(string prefix)
        {
            loadPropertyFile(prefix);
        }

        private void loadPropertyFile(string prefix)
        {
            string filename = "data_" + prefix + ".properties";
            foreach (var row in File.ReadAllLines(filename))
                data.Add(row.Split('=')[0], string.Join("=", row.Split('=').Skip(1).ToArray()));  //Here when I debug it has 15 elements, but in child class it shows '0'.           
        }
    }
}

Thanks and Regards,
Rohit pol


Answers (1)