472,805 Members | 1,665 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 1173
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.