在项目中有这样的代码:
Cookie CookieCreate(CookiesTypes type)
{
Cookie user_cookie = null;
switch (type)
{
case CookiesTypes.SessionId:
user_cookie = new Cookie("session_id", Convert.ToBase64String(Guid.NewGuid().ToByteArray()));
break;
case CookiesTypes.ClientIp:
HttpListenerContext context = listener.GetContext();
user_cookie = new Cookie("client_ip", context.Request.RemoteEndPoint.ToString());
break;
}
return user_cookie;
}
我明白,那个 temp 变量user_cookie
的语法不好......我return
在两种情况下都尝试在 switch-block 中使用,但是当我尝试这样做时,我遇到了编译器错误:
伪代码:
case ... :
//some action
return var;