Connection string

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Anyone know why the word "New" is required ?

Dim cn As OleDbConnection

cn = New OleDbConnection
 
Rob said:
Anyone know why the word "New" is required ?

Dim cn As OleDbConnection

cn = New OleDbConnection

It's required to create a new instance of the class 'OleDbConnection'. Note
that 'New' is not required for value types like structures.
 
Yes.

There is a big difference between an object and a reference to that object.

10 different variables can reference the same object. But there would be
only one object in memory.

This is quite different from having each variable point to a different
object, and there being 10 actual objects in memory.

So, with New, you specify you want to create an instance of an object. If
you don't need a new instance, because you are using that variable to point
to an existing one, then you wouldn't want to use the new operator to create
one.
 
Rob,

An other explanation.

You need memoryplaces in your program to hold whatever.

This can be a real value or a reference to something.

(whatever scope) a as whatever

This creates a fixed part of memory in a program(in a stack or whatever), it
knows what it is because you tell what it is. If it is a class than it is a
place to be able to set the reference address to the object.

a = new mywhateverclass tells that the refence is to a new object instanced
from that class.

VB Net has that nice command that does this in one time. In C# this does not
exist.

(whatever scope) a as new mywhateverclass.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top