Call non-static method from static method c# [dupl

2019-02-18 00:40发布

Possible Duplicate:
Call non-static method from static method c#

We can call non-static method from static method creating instance. Code:

public class Foo
{
    public void Data1()
    {
    }

    public static void Data2()
    {
        Foo foo = new Foo();
        foo.Data1();
    }
}

However, I heard that non-static method can be called from static method with the help of delegate. is it true? If yes, then how? Please guide me with sample code. Thanks.

标签: c# oop
7条回答
beautiful°
2楼-- · 2019-02-18 01:28

To call a non static method you need an instance of the object - there is no way around that.

查看更多
登录 后发表回答