M
Mythran
Here is some code the provides some really interesting results! First, read
over the two methods in class 'A' and compare. Just by looking at them,
both results appear to return the EXACT same information the same way. But
the appearances are deceiving! Copy and paste into a console application,
then set the configuration to Release mode
using System;
using System.Diagnostics;
using System.Reflection;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(A.DoIt1());
Console.WriteLine(A.DoIt2());
}
}
public class A
{
public static string DoIt1()
{
StackTrace trace = new StackTrace();
StackFrame frame = trace.GetFrame(0);
MethodBase method = frame.GetMethod();
return method.Name;
}
public static string DoIt2()
{
StackTrace trace = new StackTrace();
StackFrame frame = trace.GetFrame(0);
MethodBase method = frame.GetMethod();
int i = 0; i++;
return method.Name;
}
}
}
Very interesting ... anywho, comments or explanations?
Mythran
over the two methods in class 'A' and compare. Just by looking at them,
both results appear to return the EXACT same information the same way. But
the appearances are deceiving! Copy and paste into a console application,
then set the configuration to Release mode
using System;
using System.Diagnostics;
using System.Reflection;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(A.DoIt1());
Console.WriteLine(A.DoIt2());
}
}
public class A
{
public static string DoIt1()
{
StackTrace trace = new StackTrace();
StackFrame frame = trace.GetFrame(0);
MethodBase method = frame.GetMethod();
return method.Name;
}
public static string DoIt2()
{
StackTrace trace = new StackTrace();
StackFrame frame = trace.GetFrame(0);
MethodBase method = frame.GetMethod();
int i = 0; i++;
return method.Name;
}
}
}
Very interesting ... anywho, comments or explanations?
Mythran