我將一個來自服務器的消息傳遞給一個名爲strObject的字符串變量。我希望將strObject中的字符串轉換爲大寫。所以,我使用ToUpper()方法。但是,當我添加一個斷點並通過該行時,我的字符串不會轉換爲大寫字母。 strObject變量將始終包含文本Task_status。我希望將其轉換爲TASK_STATUS。我錯過了什麼?發佈我的相關代碼如下: -ToUpper()方法不起作用
public void VerifyValue(String strObject, String strValue, int row)
{
strObject.ToUpper().Trim();
strValue.ToUpper().Trim();
switch (strObject)
{
case "TASK_STATUS":
if (m_taskStatus.taskStatus.ToString() == strValue)
{
ExcelRecorder(null, row);
}
else
{
ExcelRecorder("The value [" + m_taskStatus.taskStatus.ToString() + "] does not match with the given value.", row);
}
}
}
.NET字符串不可變。 – leppie 2012-07-09 10:20:31
http://stackoverflow.com/questions/2365272/why-net-string-is-immutable – 2012-07-09 10:21:31