请教一下 VB.NET Select Case 的问题

aeeq123 2017-06-19 12:34:10
在 vb.net 项目下用 Select Case String 反编译后变成了 IF Else,Select Case Integer 就不会 有什么办法可以优化一下
VB.NET 源码

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim mtd As String = Context.Request.QueryString("mtd")
Dim text As String = mtd
Select Case text
Case "1"
Context.Response.Write("1")
Return
Case "2"
Context.Response.Write("2")
Return
Case "3"
Context.Response.Write("3")
Return
Case "4"
Context.Response.Write("4")
Return
Case "5"
Context.Response.Write("5")
Return
Case "6"
Context.Response.Write("6")
Return
Case "7"
Context.Response.Write("7")
Return
End Select
Context.Response.Write("else")
End Sub


反编译,成了 IF ELSE 了

	Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim text As String = Me.Context.Request.QueryString("mtd")
Dim text2 As String = text
Dim left As String = text2
If Operators.CompareString(left, "1", False) = 0 Then
Me.Context.Response.Write("1")
Return
End If
If Operators.CompareString(left, "2", False) = 0 Then
Me.Context.Response.Write("2")
Return
End If
If Operators.CompareString(left, "3", False) = 0 Then
Me.Context.Response.Write("3")
Return
End If
If Operators.CompareString(left, "4", False) = 0 Then
Me.Context.Response.Write("4")
Return
End If
If Operators.CompareString(left, "5", False) = 0 Then
Me.Context.Response.Write("5")
Return
End If
If Operators.CompareString(left, "6", False) = 0 Then
Me.Context.Response.Write("6")
Return
End If
If Operators.CompareString(left, "7", False) = 0 Then
Me.Context.Response.Write("7")
Return
End If
Me.Context.Response.Write("else")
End Sub


C# 的就不会
源码
 public void ProcessRequest(HttpContext context)
{
string mtd = context.Request.QueryString["mtd"];
switch (mtd)
{
case "1":
context.Response.Write("1");
break;
case "2":
context.Response.Write("2"); break;
case "3":
context.Response.Write("3"); break;
case "4":
context.Response.Write("4"); break;
case "5":
context.Response.Write("5"); break;
case "6":
context.Response.Write("6"); break;
case "7":
context.Response.Write("7"); break;
default:
context.Response.Write("else"); break;
break;

}
}


反编译后

public void ProcessRequest(HttpContext context)
{
string mtd = context.Request.QueryString["mtd"];
string text = mtd;
switch (text)
{
case "1":
context.Response.Write("1");
return;
case "2":
context.Response.Write("2");
return;
case "3":
context.Response.Write("3");
return;
case "4":
context.Response.Write("4");
return;
case "5":
context.Response.Write("5");
return;
case "6":
context.Response.Write("6");
return;
case "7":
context.Response.Write("7");
return;
}
context.Response.Write("else");
}
...全文
299 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zj_zwl 2017-06-20
  • 打赏
  • 举报
回复
case里的return是多余的
aeeq123 2017-06-20
  • 打赏
  • 举报
回复
反编译用的是ILSpy,直接百度搜索
OneCoderr 2017-06-20
  • 打赏
  • 举报
回复
我感兴趣的是你用的什么反编译软件? 能否给个链接,下来玩玩

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧