I have a basic oop question:
I use (for example in the sharepoint development) at the beginning of an operation a New constructor, but later not. For example:
' CREATES A INSTANCE OF SPSITE FROM GIVEN URL '
Dim site As spsite = New spsite("http://myhost")
' HERE I DO NOT NEED TO USE NEW(...) AND IT RETURNS AN SPSITE OBJECT, '
' A NEW SPSITE OBJECT '
Dim web As spweb = site.openweb()
My question: Why do i need at the first object of site the use of new, and in the second line not!?
I don’t really understand your problem, but if both lines are in your code (and they should be) then it works like this:
This first line creates a new spsite object, which you can access with the variable named: site
Here you create a new spweb variable, by invoking the openweb() method of your previously created site variable. This is a function call. this function returns an spweb instance so you don’t need a new one.
openweb() either has a new spweb() inside it, or the new spsite(“myhost”) created a new openweb for you (this you don’t have to know, you just know, you’ll get an spweb object)