Finding the variable name passed to a function

前端 未结 17 1973
广开言路
广开言路 2020-11-22 04:11

Let me use the following example to explain my question:

public string ExampleFunction(string Variable) {
    return something;
}

string WhatIsMyName = "         


        
17条回答
  •  灰色年华
    2020-11-22 04:43

    Thanks for all the responses. I guess I'll just have to go with what I'm doing now.

    For those who wanted to know why I asked the above question. I have the following function:

    string sMessages(ArrayList aMessages, String sType) {
        string sReturn = String.Empty;
        if (aMessages.Count > 0) {
            sReturn += "

    "; for (int i = 0; i < aMessages.Count; i++) { sReturn += aMessages[i] + "
    "; } sReturn += "

    "; } return sReturn; }

    I send it an array of error messages and a css class which is then returned as a string for a webpage.

    Every time I call this function, I have to define sType. Something like:

    output += sMessages(aErrors, "errors");
    

    As you can see, my variables is called aErrors and my css class is called errors. I was hoping my cold could figure out what class to use based on the variable name I sent it.

    Again, thanks for all the responses.

提交回复
热议问题