0
string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + ","  + false +  ")"

res[0] = "IRS5555"
res[1] = "IRS001"

这段代码的输出是:

CalcAPI.GetXElementValue("IRS5555","IRS001",False)

但我想要

CalcAPI.GetXElementValue("IRS5555","IRS001",false)

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") +  ")"

那么结果是

 CalcAPI.GetXElementValue("IRS5555","IRS001",False)

但我想要

 CalcAPI.GetXElementValue("IRS5555","IRS001",false)

如果我通过双倍

 string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + ","  + GetElementDataType("double") +  ")"

那么结果是

CalcAPI.GetXElementValue("IRS5555","IRS001",0)

但我想要

CalcAPI.GetXElementValue("IRS5555","IRS001",0.0)

如果我通过字符串

string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + ","  + GetElementDataType("string") +  ")"

那么结果是

CalcAPI.GetXElementValue("IRS5555","IRS001",)

但我想要

CalcAPI.GetXElementValue("IRS5555","IRS001","")
4

4 回答 4

5

如果您的 false 在那里保持不变,那么您可以使用简单的字符串。最好使用字符串格式:

string res1 = string.Format("CalcAPI.GetXElementValue(\"{0}\",\"{1}\",false)", res[0], res[1]);
于 2012-08-27T08:29:27.123 回答
1

使用false.ToString().ToLower().

于 2012-08-27T08:26:44.783 回答
0

尝试

false.ToString().ToLower()
于 2012-08-27T08:27:55.610 回答
0

像这样使用 ToLower() 函数

  string res1 = "CalcAPI.GetXElementValue(" + "\"" + res[0] + "\"" + "," + "\"" + res[1] + "\"" + ","  + false.ToString().ToLower() +  ")"
于 2012-08-27T08:26:37.700 回答