C#菜鸟求解
public class Chat
{
public Chat()
{
}
static protected ArrayList pArray = new ArrayList();
static public void AddMessage(string sDealer, string sUser, string sMsg)
{
string sAddText = sDealer + "*" + sUser + "*" + sMsg + "<br>";
pArray.Add(sAddText);
if (pArray.Count > 20)
{
pArray.RemoveRange(0, 10);
}
}
static public string GetAllMessages(string sDealer)
{
string sResponse = "";
for (int i = 0; i < pArray.Count; i++)
{
sResponse = sResponse +
FormatChat(pArray[i].ToString(), sDealer);
}
return (sResponse);
}
static private string FormatChat(string sLine, string sDealer)
{
int iFirst = sLine.IndexOf("*");
int iLast = sLine.LastIndexOf("*");
string sDeal = sLine.Substring(0, iFirst);
if (sDeal != sDealer)
return ("");
string sUser = sLine.Substring(iFirst + 1, iLast - (iFirst + 1));
string sMsg = sLine.Substring(iLast + 1);
string sRet = "<B>" + sUser + ": </B>" + sMsg + "";
return (sRet);
}
}
这里GetAllMessages中的string sResponse = ""是什么意思,带个双引号是干嘛
------解决方案--------------------将字符串变量初始化为空字符串
------解决方案--------------------初始化string变量
等同于 string sResponse = string.Empty;
------解决方案--------------------sResponse 是 GetAllMessages() 这个函数的返回值,大概是用于存储聊天的信息数据。
string sResponse = "" 只是声明字符串变量。