Getting the instance that called the method in C#

后端 未结 5 1421
有刺的猬
有刺的猬 2021-02-18 16:05

I am looking for an algorithm that can get the object that called the method, within that method.

For instance:

public class Class1 {

    public void Me         


        
5条回答
  •  误落风尘
    2021-02-18 16:40

    or just pass the object as method parameter.

    public void Method(object callerObject)
    {
    ..
    }
    

    and call the Method:

    myClass.Method(this);
    

    regards, Florian

提交回复
热议问题