问题描述
使用VB.NET函数IIF或c#
运算符之间的区别是什么?
VB.NET:a = iif(b = c, d,e)
C#:a =(b == c)?d:e
TIA,z。
在VB.NET中,''d''和'' e''将被评估并装入''对象''。
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://dotnet.mvps.org/dotnet/faqs/>
看看IL代码(附后)
简而言之:C#有更快的解决方案。
VB.NET:
..maxstack 3
.locals init([0] int16 a,
[1] int16 b,
[2] int16 c,
[3] int16 d,
[4] int16 e)
IL_0000:nop
IL_0001:ldloc.1
IL_0002:ldloc.2
IL_0003:ceq
IL_0005:ldloc.3
IL_0006:box [mscorlib]系统。 Int16
IL_000b:ldloc.se
IL_000d:box [mscorlib] System.Int16
IL_0012:调用对象[Microsoft.VisualBasic]
Microsoft.VisualBasic.Interaction :: IIf(bool,object,object)
IL_0017:调用int16 [Microsoft.VisualBasic]
Micr osoft.VisualBasic.CompilerServices.ShortType :: FromObject(object)
IL_001c:stloc.0
IL_001d:nop
IL_001e:ret
C#:
..maxstack 2
.locals init([0] int32 a,
[1] int32 b,
[2] int32 c,
[3] int32 d,
[4] int32 e)
IL_0000:ldc.i4.0
IL_0001:stloc.1
IL_0002:ldc.i4.0
IL_0003:stloc.2
IL_0004:ldc.i4.0
IL_0005:stloc.3
IL_0006:ldc.i4。 0
IL_0007:stloc.se
IL_0009:ldloc.1
IL_000a:ldloc.2
IL_000b: beq.s IL_0011
IL_000d:ldloc.se
IL_000f:br.s IL_0012
IL_0011:ldloc.3
IL_0012:stloc.0
IL_0013:ret
-
问候
Jochen
what''s the difference between using the VB.NET function IIF or the c#
operator ?
VB.NET: a = iif ( b=c, d, e)
C#: a= (b==c)?d:e
TIA, z.
In VB.NET, ''d'' and ''e'' will be evaluated and boxed in an ''Object''.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Just look at the IL code (appended)
In short: C# has the faster solution.
VB.NET:
..maxstack 3
.locals init ([0] int16 a,
[1] int16 b,
[2] int16 c,
[3] int16 d,
[4] int16 e)
IL_0000: nop
IL_0001: ldloc.1
IL_0002: ldloc.2
IL_0003: ceq
IL_0005: ldloc.3
IL_0006: box [mscorlib]System.Int16
IL_000b: ldloc.s e
IL_000d: box [mscorlib]System.Int16
IL_0012: call object [Microsoft.VisualBasic]
Microsoft.VisualBasic.Interaction::IIf(bool, object, object)
IL_0017: call int16 [Microsoft.VisualBasic]
Microsoft.VisualBasic.CompilerServices.ShortType:: FromObject(object)
IL_001c: stloc.0
IL_001d: nop
IL_001e: ret
C#:
..maxstack 2
.locals init ([0] int32 a,
[1] int32 b,
[2] int32 c,
[3] int32 d,
[4] int32 e)
IL_0000: ldc.i4.0
IL_0001: stloc.1
IL_0002: ldc.i4.0
IL_0003: stloc.2
IL_0004: ldc.i4.0
IL_0005: stloc.3
IL_0006: ldc.i4.0
IL_0007: stloc.s e
IL_0009: ldloc.1
IL_000a: ldloc.2
IL_000b: beq.s IL_0011
IL_000d: ldloc.s e
IL_000f: br.s IL_0012
IL_0011: ldloc.3
IL_0012: stloc.0
IL_0013: ret
--
Greetings
Jochen
这篇关于有什么不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!