Converting to string


I want to convert the name of a variable to a string, not the variable it stores!

for example:

public string Istorehello;
public string hello;

now I want to set the variable “hello” to a string, (not the value),
so that we would get following:

void Update()
Istorehello = “hello”;

My problem is that I just know how to handle here with the value of that string, not with itselve…

Thanks for each answer!


Here you go :

using UnityEngine;
using System;
using System.Linq.Expressions;

public class NewBehaviourScript : MonoBehaviour 

    static string GetVariableName<T>(Expression<Func<T>> expr)
        var body = (MemberExpression)expr.Body;

        return body.Member.Name;

	void Start () 
        int test = 0;
        print(GetVariableName(() => test));