473,320 Members | 1,961 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,320 software developers and data experts.

how to create class instance?

Hi,

i defined a class "myclass" in the App_Code directory of my asp.net
application.

i tried both syntaxes and both work.
My question is: is there a difference between both lines and what's the
best?

dim x as new myclass
dim x as new myclass()

Thanks
André
Mar 15 '07 #1
4 10655
On 15 Mar, 09:21, "André" <a...@dre.tywrote:
Hi,

i defined a class "myclass" in the App_Code directory of my asp.net
application.

i tried both syntaxes and both work.
My question is: is there a difference between both lines and what's the
best?

dim x as new myclass
dim x as new myclass()

Thanks
André
I would say without the brackets unless you have arguments that need
to be entered in the constructor then you need the brackets.

But at the end of the day its just personal preference.

Mar 15 '07 #2
"André" <an@dre.tyschrieb:
i defined a class "myclass" in the App_Code directory of my asp.net
application.

i tried both syntaxes and both work.
My question is: is there a difference between both lines and what's the
best?

dim x as new myclass
dim x as new myclass()

Both lines are semantically identical. Personally I prefer the second one
for consistency. VB does not enforce empty parentheses on method
(constructor) calls.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 15 '07 #3
On Mar 15, 10:00 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"André" <a...@dre.tyschrieb:
i defined a class "myclass" in the App_Code directory of my asp.net
application.
i tried both syntaxes and both work.
My question is: is there a difference between both lines and what's the
best?
dim x as new myclass
dim x as new myclass()

Both lines are semantically identical. Personally I prefer the second one
for consistency. VB does not enforce empty parentheses on method
(constructor) calls.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Agreed.

However, it's worth noting that if your class only provides a default
(parameterless) constructor, and you're using Visual Studio .NET
2002/2003, the IDE will remove the empty parentheses automatically.
It's annoying. I prefer to put them in there. (A call to the default
constructor is still, technically, a method call.)
Mar 15 '07 #4
Thanks

"Mike Hofer" <kc********@gmail.comschreef in bericht
news:11**********************@n76g2000hsh.googlegr oups.com...
On Mar 15, 10:00 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"André" <a...@dre.tyschrieb:
i defined a class "myclass" in the App_Code directory of my asp.net
application.
i tried both syntaxes and both work.
My question is: is there a difference between both lines and what's the
best?
dim x as new myclass
dim x as new myclass()

Both lines are semantically identical. Personally I prefer the second one
for consistency. VB does not enforce empty parentheses on method
(constructor) calls.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Agreed.

However, it's worth noting that if your class only provides a default
(parameterless) constructor, and you're using Visual Studio .NET
2002/2003, the IDE will remove the empty parentheses automatically.
It's annoying. I prefer to put them in there. (A call to the default
constructor is still, technically, a method call.)

Mar 15 '07 #5

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

Similar topics

14
by: Sridhar R | last post by:
Consider the code below, class Base(object): pass class Derived(object): def __new__(cls, *args, **kwds): # some_factory returns an instance of Base # and I have to derive from this...
7
by: Steven.Xu | last post by:
Hello everyone! I have a problem about create an instance automatically in C#. Now I have a class: namespace1.namespace11.CClass01. I want to create it's instance in a function named...
7
by: Göran Tänzer | last post by:
Hi, i've written a class which does some calculations for my web application. These informatinos are different for each page request - the current user is not important. i have about 10 aspx...
6
by: Rene Mansveld | last post by:
Hi, how can I create an instance (object) of a class (form) if I only know the classname (VB.NET 1.0)? I need to do this in a complex app where jobs consist of parts. Each part's data is saved...
18
by: Sandra-24 | last post by:
Can you create an instance of a subclass using an existing instance of the base class? Such things would be impossible in some languages or very difficult in others. I wonder if this can be done...
2
by: TEK | last post by:
Hello We're having a issue with a part of our app that is very strange, and I'm unable to see that it should be possible. We have: A collection (ActivityCollection) that is inherited from a...
11
by: teel | last post by:
Hi there, I need to create an instance of a class whose name I have in a string variable, let's say that: string myTypeName = "MyType"; and in a result I need the equivalent of: MyType obj =...
4
by: sirjohnofthewest | last post by:
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man. Hi guys, I frequently visit this site to get answers to my...
1
by: Scott Izu | last post by:
'Method 1 Dim Form1 As Form = Activator.CreateInstance(Of frmContractEdit)() Form1.Show() 'Method 2 Dim Form2Type As Type = GetType(frmContractEdit) MsgBox(Form2Type.AssemblyQualifiedName)...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.