Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Retrieve Data in derived class (Inheritance)

$
0
0

Hi everybody,
I need a help with get data from inheritance/derived item, follows my code:

namespace A
{
    public class Common_Data
    {
        public class Derived_Component : Base_Components
        {
            public string derived_component_name;

            public Derived_Component()
            {
                base_component_name = "A";
                derived_component_name = "B";
            }
        }

        public abstract class Base_Components
        {
            public string base_component_name;
        }
    }

    public class Run
    {
        public Run()
        {
            List<Common_Data.Base_Components> list = new List<Common_Data.Base_Components>();
            Common_Data.Derived_Component derived = new Common_Data.Derived_Component();
            list.Add(derived);

            foreach(Common_Data.Base_Components bs in list) 
            {
                string _base = bs.base_component_name;
                string _derived = bs.derived_component_name;
            }

        }
    }
}

I can't retrieve the derived component name in my list, how can make right?



Raphael Pugliesi


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>