Maybe this information is usefull for you.
Since you want the value and the name of the property that has changed you could move the method dosomething inside the setter of the property.
(Notice: I am assuming you are actually working with properties and not local variables as shown in your question, and your question is just simplified)
So something like this:
public class Foo
{
private string _myVar1;
public string MyVar1
{
get => _myVar1;
set
{
_myVar1 = value;
DoSomething(value);
}
}
private void DoSomething(string value, [CallerMemberName]string propertyName = "")
{
Console.WriteLine(value);
Console.WriteLine(propertyName);
}
}
The attribute CallerMemberName requires the using System.Runtime.CompilerServices
More Information can be found here: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.callermembernameattribute
See it in action here: https://dotnetfiddle.net/YvqqdP