views:

59

answers:

4

i can not see MyLoad.TreeLoader(.... but why i can not see? i implemented iloader to TreeViewLoad. i should see TreeLoader why?

namespace Rekursive
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //treeView1.Nodes.Add("Test");
            iloader MyLoad = new TreeViewLoad();
            MyLoad.loader("test", treeView1, 1);
           // i can not  see MyLoad.TreeLoader(.... but why i can not see?
            // i implemented iloader to TreeViewLoad. i should see TreeLoader why?
        //TreeViewLoad myloader = new TreeViewLoad();
        }
    }

    interface iloader
    {
        void loader(string nodeName, TreeView myTre, int id);
    }

    class TreeViewLoad : iloader
    {
       public void TreeLoader(TreeView tre)
        {
           // i will call loader...
        }


        public void loader(string nodeName, TreeView myTre, int id)
        {

            myTre.Nodes.Add(nodeName + id.ToString());
            if (id 
+2  A: 

you declare MyLoad variable as iloader interface so you can see only the interface methods here. To see TreeLoader method declare MyLoad of TreeViewLoad type

Arseny
+5  A: 

You are referring to the object through the interface, which means you only have access to the interface's methods and properties. The interface has a void loader method, TreeLoader belongs to the TreeViewLoad class.

TreeViewLoad myLoader = new TreeViewLoad();
// now you can access loader and TreeLoader.
Anthony Pegram
i can not :)....
Phsika
i want to that: iloader MyLoad = new TreeViewLoad();
Phsika
+1  A: 

You declared the variable MyLoad to be of the interface type ILoader (I changed it from iloder to the more common convention for readability) and TreeLoader() is not a member of this interface and therefore you cannot access it. You can access it, if you cast the variable to TreeViewLoad.

ILoader myLoad = new TreeViewLoad();

((TreeViewLoad)myLoad).TreeLoader(...);

But you should rethink your design - you should usually not have to cast an interface to the concrete type and the fact that you have to indicates that something may be wrong.

Daniel Brückner
A: 

This is my answer:

namespace Rekursive
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            iloader MyLoad = new TreeViewLoad();
            ((TreeViewLoad)MyLoad).TreeLoader(treeView1);
        }
    }

    interface iloader
    {
        void loader(string nodeName, TreeView myTre, int id);
    }

    class TreeViewLoad : iloader
    {
        public void TreeLoader(TreeView myTre)
        {
            loader("test", myTre, 1);
        }


        public void loader(string nodeName, TreeView myTre, int id)
        {

            myTre.Nodes.Add(nodeName + id.ToString());
            if (id 
Phsika