Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my class method not visible when I implement an interface in my class?

I cannot see MyLoad.TreeLoader(), but why? I have implemented iloader to TreeViewLoad. I should be able to see TreeLoader().

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);
        }
    }

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

    class TreeViewLoad : iloader
    {
       public void TreeLoader(TreeView tre)
        {
           // Here I want to call the loader
        }

        public void loader(string nodeName, TreeView myTre, int id)
        {
            myTre.Nodes.Add(nodeName + id.ToString());
            if (id < 10)
            {
                id++;
                loader(nodeName, myTre, id);
            }
        }
    }
}
like image 560
ALEXALEXIYEV Avatar asked Jan 29 '26 08:01

ALEXALEXIYEV


2 Answers

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.
like image 81
Anthony Pegram Avatar answered Jan 30 '26 20:01

Anthony Pegram


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

like image 43
Arseny Avatar answered Jan 30 '26 20:01

Arseny