title: C# get the name of a method that called another one
body: <p>Here is my problem: I have two classes which each include a method. Method 1 of class 1 calls method 2 of class 2.
  Now, I need to store in a local variable of method 2 (of type string probably), the name of the method that called method 2 (i.e. Method1).</p>
  <p>For this I have set up a global variable named string str in class 2. However, as we create a new instance of class 2 when we call method 2, we have: str=null.</p>
  <p>Here is the code so that you understand the problem:</p>
  <pre><code>public class Class1
      {
          private Class2 _class2 = new Class2();
          public Class2 Class2 { get =&gt; _class2; set =&gt; _class2 = value; }
  
          public void Method1()
          {
              Class2.data = &quot;Changes I want to Make in Class2&quot;;
              Class2.Method2();
          }
      }
  public class Class2
      {
          public string data;
  
          public void Method2()
          {
              string str = data; //str=null instead of str=&quot;Changes I want to Make in Class2&quot;
              //Rest of the code here
          }
      }
  </code></pre>
  <p>I know that str=null since I instantiate the object Class2 = new Class2().</p>
  <p>So, I need to find another way around the problem, and I realised that, in my case, <strong>getting the name of Method 1 from a local variable in Method 2 would be a solution.</strong></p>
  <p>My question is therefore the following: Is there a way to answer this problem?</p>
  <p>Note: I am a beginner in computer development, so I apologise in advance if the solution is easy and I have not seen it before.</p>