Re: runtime stack



There is no difference.  They will both produce identical IL code.

This isn't related to the stack. The stack would be relevant if you were concerned about the number of variables you are using within a method.

If you want to see for yourself that they are exactly the same (and learn how to figure these things out), copy the following text to a file (test.cs):

using System;
public class StackTest {
 public void FirstTry(string varone){
  if(varone != null)
  if(varone != "")
  dosomething();
 }
	
 public void SecondTry(string varone){
  if(varone != null && varone!= "")
  dosomething();
 }

 public void dosomething(){
  Console.WriteLine("hello");
 }
}

Compile from the command line:
csc /t:library /out:test.dll test.cs

Load the library in the IL Disassembler:
ildasm test.dll

Double click on FirstTry. Double click on SecondTry. Compare the contents of the 2 windows that popped up. The instructions are the same.


Joshua Flanagan http://flimflan.com/blog .



Relevant Pages

  • Re: runtime stack
    ... I cannot think of what you may have read that would have related the construction of conditional statements with the stack. ... ifdosomething();} ... public void SecondTry(string varone){ ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: runtime stack
    ... Do you know of any resources where I can read about the stack? ... > dosomething(); ... > public void SecondTry(string varone){ ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# Reflection--anybody use it lately?
    ... public void DoSomething() ... public void DoSomethingElse() ... This AOP approach only uses reflection during compile time and not runtime, additionally I will say that if you think AOP is only related to security then either that URL is no good or you misunderstood it. ... Tut tut. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: finalize()
    ... public void doSomething() throws Exception { ... File file = null; ... You failed to catch the Exception that doSomethingmight throw. ...
    (comp.lang.java.programmer)
  • Re: extending class that is not in a packed
    ... Now I am using reflect to extend this class ... >> public void DoSomething(){ ... >> and class Class2 that is ... >> public void DoSomething2(){ ...
    (comp.lang.java)