字符串连接

jat*_*ats 0 c#

string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + ","  + false +  ")"
Run Code Online (Sandbox Code Playgroud)

res[0] = "IRS5555"
res[1] = "IRS001"
Run Code Online (Sandbox Code Playgroud)

此代码的输出是:

CalcAPI.GetXElementValue("IRS5555","IRS001",False)
Run Code Online (Sandbox Code Playgroud)

但我想要

CalcAPI.GetXElementValue("IRS5555","IRS001",false)
Run Code Online (Sandbox Code Playgroud)

false 小写的.

很抱歉没有提供完整的代码... false不是静态的...

    public static object GetElementDataType(string DataType)
     {
         ///Write here methos for fetching data type of current element.
          object res = null;
         switch (DataType.ToLower())
          {
              case "int":
                 res = 0;
                 break;
              case "double":
                 res = 0.0;
                 break;
              case "string":
                 res = "";
                 break;
              case "myboolean":
                 res = false;
                 break;
              default:
                 res = "";
                 break;
          }
         return res;
     }

     string res1 = 
         "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," 
                                     + "\"" + res[1] + "\"" + ","  
                                     + GetElementDataType("myboolean") +  ")"
Run Code Online (Sandbox Code Playgroud)

然后结果是

 CalcAPI.GetXElementValue("IRS5555","IRS001",False)
Run Code Online (Sandbox Code Playgroud)

但我想要

 CalcAPI.GetXElementValue("IRS5555","IRS001",false)
Run Code Online (Sandbox Code Playgroud)

如果我通过双倍

 string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + ","  + GetElementDataType("double") +  ")"
Run Code Online (Sandbox Code Playgroud)

然后结果是

CalcAPI.GetXElementValue("IRS5555","IRS001",0)
Run Code Online (Sandbox Code Playgroud)

但我想要

CalcAPI.GetXElementValue("IRS5555","IRS001",0.0)
Run Code Online (Sandbox Code Playgroud)

如果我传递字符串

string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + ","  + GetElementDataType("string") +  ")"
Run Code Online (Sandbox Code Playgroud)

然后结果是

CalcAPI.GetXElementValue("IRS5555","IRS001",)
Run Code Online (Sandbox Code Playgroud)

但我想要

CalcAPI.GetXElementValue("IRS5555","IRS001","")
Run Code Online (Sandbox Code Playgroud)

Jle*_*HeP 5

如果你的假是常数,那么你可以使用简单的字符串.最好使用字符串格式:

string res1 = string.Format("CalcAPI.GetXElementValue(\"{0}\",\"{1}\",false)", res[0], res[1]);
Run Code Online (Sandbox Code Playgroud)