473,386 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Which is better?

With respect to performance, is either of these better?

Dim myTextBox As New TextBox

or

Dim myTextBox As TextBox
myTextBox = New TextBox

or

Dim myTextBox As TextBox = New TextBox
Nov 18 '05 #1
3 1193
It's unlikely you'll ever see a difference (you could even see if it doesn't
create the same underlying MSIL code).

This is the same (unlike VB6 were New was checking for existence at each
access to the variable). 2 may be usefull as it allows to create an object
only when (and in particular *if*) you need it which could could save some
time (under unusual circumstances though it's likely best to avoid creating
something if you don't need it).

As a side note it's likely most often considered better to code for clarity
and to work on identified performance problem rather than to be picky about
few microseconds gains... For example if you use a DB it's likely better to
start by looking at indexes design...
Patrice

--

"Paul" <pa*******@smmoving.com> a écrit dans le message de
news:%2****************@TK2MSFTNGP11.phx.gbl...
With respect to performance, is either of these better?

Dim myTextBox As New TextBox

or

Dim myTextBox As TextBox
myTextBox = New TextBox

or

Dim myTextBox As TextBox = New TextBox

Nov 18 '05 #2
Numbers 1 and 3 are better in terms of performance (not sure if either of
them is better than the other). However, it is minimal.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Paul" <pa*******@smmoving.com> wrote in message
news:#1**************@TK2MSFTNGP11.phx.gbl...
With respect to performance, is either of these better?

Dim myTextBox As New TextBox

or

Dim myTextBox As TextBox
myTextBox = New TextBox

or

Dim myTextBox As TextBox = New TextBox

Nov 18 '05 #3
Hey Kevin,
I'm pretty sure the three are identical:

..method private instance void test() cil managed
{
// Code Size: 21 byte(s)
.maxstack 1
.locals (
[System.Web]System.Web.UI.WebControls.TextBox box1,
[System.Web]System.Web.UI.WebControls.TextBox box2,
[System.Web]System.Web.UI.WebControls.TextBox box3)
L_0000: nop
L_0001: newobj instance void
[System.Web]System.Web.UI.WebControls.TextBox::.ctor()
L_0006: stloc.0
L_0007: newobj instance void
[System.Web]System.Web.UI.WebControls.TextBox::.ctor()
L_000c: stloc.1
L_000d: newobj instance void
[System.Web]System.Web.UI.WebControls.TextBox::.ctor()
L_0012: stloc.2
L_0013: nop
L_0014: ret
}
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Numbers 1 and 3 are better in terms of performance (not sure if either of
them is better than the other). However, it is minimal.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Paul" <pa*******@smmoving.com> wrote in message
news:#1**************@TK2MSFTNGP11.phx.gbl...
With respect to performance, is either of these better?

Dim myTextBox As New TextBox

or

Dim myTextBox As TextBox
myTextBox = New TextBox

or

Dim myTextBox As TextBox = New TextBox


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
6
by: lastusernameleft | last post by:
i've been researching this issue for a while and can't come to any conclusive answer, mostly it seems to be a preference over syntax, some saying c# is elegant while vb is clunky, or that c# is...
1
by: Markus Rebbert | last post by:
Hi list, i got an postgresql installation on linux (debian) with the htree partitions: 1- system 2- postgresql data files 3- postgresql WAL logs(pg_xferlog) Our standard file system is...
4
by: Ed Davis | last post by:
I'm trying to decide which of the following programming styles is better, as in easier to understand, and thus easier to maintain. Keep in mind that for posting purposes, this is a greatly...
9
by: Robert Lario | last post by:
C# verses VB.Net Which Way to go. I am sure this issues has come up before. Please direct me to any good articles that cover this issue. Ideally some neutral assessment.
22
by: smartwolf agassi via DotNetMonster.com | last post by:
I'm a C# language learner. I want to know which IDE is better for C# programing, Borland C#Builder or VS.net 2003? -- Message posted via http://www.dotnetmonster.com
2
by: monkeydragon | last post by:
Which is better, using ReadFile/WriteFile or use fstream?
33
by: Protoman | last post by:
Which is better for general-purpose programming, C or C++? My friend says C++, but I'm not sure. Please enlighten me. Thanks!!!!!
48
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.