首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

IL有关问题,2段相同的代码结果却不一样

2013-03-12 
IL问题,2段相同的代码结果却不一样下面是一段IL代码。0L_0000:nop1L_0001:ldarg.32L_0002:ldc.i4.03L_0003:

IL问题,2段相同的代码结果却不一样
下面是一段IL代码。

0        L_0000:      nop          
1        L_0001:      ldarg.3      
2        L_0002:      ldc.i4.0     
3        L_0003:      newobj       System.Void System.Decimal::.ctor(System.Int32)
4        L_0008:      call         System.Boolean System.Decimal::op_LessThan(System.Decimal,System.Decimal)
5        L_000d:      ldc.i4.0     
6        L_000e:      ceq          
7        L_0010:      stloc.s      V_7
8        L_0012:      ldloc.s      V_7
9        L_0014:      brtrue.s     16 -> ldarg.2
10       L_0016:      ldarg.0      
11       L_0017:      call         System.Web.Mvc.ModelStateDictionary System.Web.Mvc.Controller::get_ModelState()
12       L_001c:      ldstr        "chargeAmount"
13       L_0021:      ldstr        "手续费必须大于等于 0 元"
14       L_0026:      callvirt     System.Void System.Web.Mvc.ModelStateDictionary::AddModelError(System.String,System.String)

翻译成C#就是
 if (chargeAmount < 0m)
   {
       base.get_ModelState().AddModelError("chargeAmount", "手续费必须大于等于 0 元");
   }


再看另一段IL代码
119      L_012d:      nop          
120      L_012e:      ldloc.s      V_5
121      L_0130:      callvirt     System.Decimal Oxite.Model.Account::get_Amount()
122      L_0135:      ldc.i4.0     
123      L_0136:      newobj       System.Void System.Decimal::.ctor(System.Int32)
124      L_013b:      call         System.Boolean System.Decimal::op_LessThanOrEqual(System.Decimal,System.Decimal)
125      L_0140:      ldc.i4.0     


126      L_0141:      ceq          
127      L_0143:      stloc.s      V_7
128      L_0145:      ldloc.s      V_7
129      L_0147:      brtrue.s     138 -> ldarg.0
130      L_0149:      ldarg.0      
131      L_014a:      call         System.Web.Mvc.ModelStateDictionary System.Web.Mvc.Controller::get_ModelState()
132      L_014f:      ldloc.s      V_4
133      L_0151:      callvirt     System.String Oxite.Model.User::get_Name()
134      L_0156:      ldstr        "押金必须大于等于余额"
135      L_015b:      call         System.String System.String::Concat(System.String,System.String)
136      L_0160:      call         System.Void Oxite.Mvc.Extensions.ControllerExtensions::AddFormError(System.Web.Mvc.ModelStateDictionary,System.String)



翻译成C#
    if (account2.get_Amount() <= 0m)
                   {
                       base.get_ModelState().AddFormError(account.get_Name() + "押金必须大于等于余额");
                   }


2段IL代码不难理解。很清晰的知道流程。唯一的疑惑就是2段相似的IL,第一段比较方式是小于,同样的代码,第2段却是小于等于。

 
引用
Ceq 比较两个值。如果这两个值相等,则将整数值 1 ((int32) 推送到计算堆栈上;否则,将 0 (int32) 推送到计算堆栈上。 


求科普,求解惑。 c# IL
[解决办法]
第二段不是写了么
124      L_013b:      call         System.Boolean System.Decimal::op_LessThanOrEqual你还想知道什么?

热点排行