Questions tagged [il]

CIL (Common Intermediate Language) is a low-level language used by Microsoft .NET Framework and Mono.

477 questions
11
votes
3 answers

Is IL generated by expression trees optimized?

Ok this is merely curiosity, serves no real world help. I know that with expression trees you can generate MSIL on the fly just like the regular C# compiler does. Since compiler can decide optimizations, I'm tempted to ask what is the case with IL…
nawfal
  • 70,104
  • 56
  • 326
  • 368
11
votes
3 answers

CIL OpCode (Ldarg_0) is used even though there are no arguments

I have the following C# code. public void HelloWorld() { Add(2, 2); } public void Add(int a, int b) { //Do something } It produces the following CIL .method public hidebysig instance void HelloWorld() cil managed { // Code size 11…
animaonline
  • 3,715
  • 5
  • 30
  • 57
11
votes
1 answer

C# Dynamic Method - IL vs Expression Trees

I'm playing and learning little with ANTLR building a simple DSL for .NET, transforming the script in string into Dynamic Method. My first idea was translate to IL opcodes, but now I am reading about expression trees for DM creation. It seems that I…
Ricardo
  • 1,549
  • 2
  • 12
  • 11
10
votes
2 answers

Does Debug.Assert generate IL in release mode?

When Debug.Assert() method calls exist in source code and I compile in release mode, does the compiler generate the IL for the Debug.Assert() even though it's not called? One of our developers added an Assert recently that displays information about…
Osiris
  • 489
  • 3
  • 14
10
votes
2 answers

What does [opt] mean in MSIL?

I found the "optional parameters" feature in C# 4.0 very interesting, so I tried to figure out how they made it happen. so I wrote a method like this: private static void A(int a = 5) { } Compiled it, then decompiled it in IL DASM, this is the IL…
Cui Pengfei 崔鹏飞
  • 8,017
  • 6
  • 46
  • 87
10
votes
1 answer

Purpose and Meaning of "specialname" and "rtspecialname" in IL

I am trying to understand the IL code and C# internals specifically nowadays, i wrote a simple c# hello world program whose code is : using System; class Program { public static void Main() { Console.WriteLine("Hello World"); …
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
10
votes
3 answers

IL code, Someone get me explain why ldarg.0 appear twice?

This is the c# code class SimpleIL { private int f = 2; public void M1() { M2(f); } public void M2(Object p) { Console.WriteLine(p); } } This is the IL of M1 method IL_0000: nop IL_0001: ldarg.0 IL_0002: ldarg.0 …
StevenS
  • 113
  • 4
10
votes
4 answers

Size of generic structure

I need to find out a size of a generic structure (I can not do it like sizeof(T) or using Marshal.SizeOf(...) 0> gives me an error) So I wrote: public static class HelperMethods { static HelperMethods() { SizeOfType =…
dajuric
  • 2,373
  • 2
  • 20
  • 43
10
votes
4 answers

IL & stack implementation in .net?

I wrote a simple program to examine how IL works : void Main() { int a=5; int b=6; if (a
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
10
votes
2 answers

DynamicMethod is much slower than compiled IL function

I wrote a simple object copier that copies public properties. I can't figure out why the Dynamic method is a lot slower than the c# version. Durations C# method : 4,963 ms Dynamic method : 19,924 ms Note that - as I run the dynamic method before…
Pascal Ganaye
  • 1,174
  • 12
  • 28
10
votes
1 answer

Difference between call instance vs newobj instance in IL

I'm delving into C# in Depth, and playing with nullable value types. Just for experimental purposes I wrote a piece of code: private static void HowNullableWorks() { int test = 3; int? implicitConversion = test; …
dragonfly
  • 17,407
  • 30
  • 110
  • 219
10
votes
5 answers

Is MSIL same as Managed Code in .NET?

I am confused with MSIL and Managed Code are they same or different? I mean to say, what happens when we built our C# code? Which one is right C# Code → C# compiler → Managed Code → MSIL or C# Code → C# compiler → MSIL Please provide authentic…
user129967
9
votes
2 answers

understand MSIL of try catch finally

I have the following code using System; class Pankaj { public static int Main() { int returnValue=0; try { return returnValue; throw new Exception(); } catch(Exception…
Pankaj
  • 1,446
  • 4
  • 19
  • 31
9
votes
1 answer

Why does this work? Executing method from IL without instance

I was looking through What's the strangest corner case you've seen in C# or .NET?, and this code made me think a little: public class Program { delegate void HelloDelegate(Strange bar); [STAThread()] public static void Main(string[]…
user3439065
  • 840
  • 5
  • 8
9
votes
2 answers

Why is a TypeBuilder generated generic methodinfo not a generic method?

I have some code that uses a MethodInfo of a generic method found on a generated type. To avoid some reflection, I have the code use the ldtoken Method ldtoken Type call GetMethodFromHandle(RuntimeMethodHandle,RunTimeTypeHandle) Pattern to…
Michael B
  • 7,512
  • 3
  • 31
  • 57