Can anyone tell me in a few words, is one of the following better and if so
which one and why:
if(varone != null)
if(varone != "")
dosomething();
if(varone != null && varone!= "")
dosomething();
I'm thinking what I need to learn more about is the "stack". Is that the
correct term? Anyone have references?
Thanks. 6 1701
Chance Hopkins wrote: Can anyone tell me in a few words, is one of the following better and if so which one and why:
if(varone != null) if(varone != "") dosomething();
if(varone != null && varone!= "") dosomething();
I'm thinking what I need to learn more about is the "stack". Is that the correct term? Anyone have references?
Thanks.
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(strin g varone){
if(varone != null && varone!= "")
dosomething();
}
public void dosomething(){
Console.WriteLi ne("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
Thanks, I will try this tomorrow when I am more awake.
Do you know of any resources where I can read about the stack? I'd like to
understand more about that too. I stumbled upon some comparison in a
newsgroup post but can't find it again and don't know where to start.
"Joshua Flanagan" <jo**@msnews.co m> wrote in message
news:u0******** ******@TK2MSFTN GP15.phx.gbl... 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(strin g varone){ if(varone != null && varone!= "") dosomething(); }
public void dosomething(){ Console.WriteLi ne("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
if(varone != null)
if(varone != "")
dosomething();
Will be translated to
if ((varone != null) && (varone != ""))
dosomething();
So it doesn't really matter. But in the first approach you could still add
an else statement if the condition varone equals "".
Gabriel Lozano-Morán
Software Engineer
Sogeti
"Chance Hopkins" <ch************ @hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. .. Can anyone tell me in a few words, is one of the following better and if so which one and why:
if(varone != null) if(varone != "") dosomething();
if(varone != null && varone!= "") dosomething();
I'm thinking what I need to learn more about is the "stack". Is that the correct term? Anyone have references?
Thanks.
What kind of information are you looking for? I cannot think of what
you may have read that would have related the construction of
conditional statements with the stack.
Any general computer science text should be able to explain the concepts
of stack allocation vs. heap allocation.
A quick search turns up this link, which explains the basics: http://www-ee.eng.hawaii.edu/Courses...on2.1.1.8.html
In .NET terms, you may have heard of "value types" (stored on the stack)
vs. "reference types" (allocated on the heap).
You can read about value types in the .NET Framework here: http://msdn.microsoft.com/library/de...guidelines.asp http://msdn.microsoft.com/library/de...ValueTypes.asp
Chance Hopkins wrote: Thanks, I will try this tomorrow when I am more awake.
Do you know of any resources where I can read about the stack? I'd like to understand more about that too. I stumbled upon some comparison in a newsgroup post but can't find it again and don't know where to start. "Joshua Flanagan" <jo**@msnews.co m> wrote in message news:u0******** ******@TK2MSFTN GP15.phx.gbl...
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(strin g varone){ if(varone != null && varone!= "") dosomething(); }
public void dosomething(){ Console.WriteLi ne("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
Joshua Flanagan <jo**@msnews.co m> wrote:
<snip> In .NET terms, you may have heard of "value types" (stored on the stack) vs. "reference types" (allocated on the heap).
Although you may have heard that, it's a commonly-stated but inaccurate
description.
See http://www.pobox.com/~skeet/csharp/memory.html
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob Bamberg |
last post by:
Hello All,
I have been trying without luck to get some information on debugging
the Runtime Error R6025 - Pure Virtual Function Call. I am working in
C++ and have only one class that is derived from an Abstract class, I
do not believe that this class object is causing me my problem. Below
is that message I have posted before to other groups.
Question:
|
by: Brian Lindahl |
last post by:
I'm using a temporary buffer to transfer some data and would rather
not allocate it on the heap. The problem is that the size of the
buffer is only known upon entry into the function that utilizes it and
I'd rather not waste space or dynamically allocate on the heap (since
it doesn't need to persist). Now I'm planning on utilizing inline
assembly to modify the stack pointer directly to allocate the space I
need.
Here's an example:
|
by: Yongsub Eric Shin |
last post by:
Hi. I'm just a beginner in ASP.Net.
I started writing codes and I keep on getting this Runtime
Error page, where it says
"Description: An application error occurred on the server.
The current custom error settings for this application
prevent the details of the application error from being
viewed remotely (for security reasons). It could, however,
be viewed by browsers running on the local server machine.
|
by: rushikesh.joshi |
last post by:
Hi All,
I have created my own WebControl and want to add it in my aspx page at
runtime.
it's compiling perfectly, but when i m going to execute, it gives me
error of "Object reference not set to an instance of an object." in my
server control (ascx.cs file)
|
by: Andrew |
last post by:
Hi,
I have a scenario in which both the source and format string for a
sscanf() call is selected *at runtime*. The number of format
conversions/substitutions is known as well as the maximum length of
each, so it's easy enough to allocate the memory required dynamically.
The problem is, how do I call sscanf()?
The only way to acheive this I can think of is to mess with the stack
| |
by: John Friedland |
last post by:
My problem: I need to call (from C code) an arbitrary C library
function, but I don't know until runtime what the function name is,
how many parameters are required, and what the parameters are. I can
use dlopen/whatever to convert the function name into a pointer to
that function, but actually calling it, with the right number of
parameters, isn't easy.
As far as I can see, there are only two solutions:
1) This one is portable. If...
|
by: sunny |
last post by:
Hi All
Is there any way to determine stack and heap size, during runtime.
i.e can we predict stack overflow. etc
|
by: Bernard Borsu |
last post by:
Hi !
I have a big problem with a asp.net 2.0 website. I've just upgrade it from
asp.net 1.1. In this previous version, no problem at all.
Now, i've a recursive error .NET Runtime 2.0 Error - ID Event 5000.
Here ise the description in the Application log :
EventType clr20r3, P1 w3wp.exe, P2 6.0.3790.3959, P3 45d6968e, P4 system, P5
|
by: mohi |
last post by:
hello every one ,
this may be very basic question and may be a bit out of topic ,,
can anyone please tell me what are the functions of runtime library
and are they the one which create the program stack, manages heap???
and how can i find out that does my compiler (or linker) produces
dynamically linked runtime libraries (if so how can i make it to do it
statically on gnu g++ on fedora c8)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |