为什么[新增"有时用构造函数,而不是其他(OOP的基本理解)时用、函数、而不是、基本

由网友(眼眶已哭红)分享简介:我有一个基本的OOP问题:I have a basic oop question:我在操作一个新构造的开始(在SharePoint开发为例)使用,但后来没有。例如:I use (for example in the sharepoint development) at the beginning of an op...

我有一个基本的OOP问题:

I have a basic oop question:

我在操作一个构造的开始(在SharePoint开发为例)使用,但后来没有。例如:

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!?

推荐答案

我真的不明白你的问题,但如果两条线是在code(以及他们应该是),那么它的工作原理是这样的: 这第一行创建一个新的SPSite对象,您可以与命名变量访问:网站

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

dim site as spsite = new spsite("http://myhost")

下面创建一个新的SPWeb变量,通过调用pviously创建的网站变的$ P $的openweb()方法。这是一个函数调用。此函数返回的SPWeb实例,所以你不需要一个新的。

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.

dim web as spweb = site.openweb()

openweb()或者有一个新的SPWeb()里面,或者新的SPSite(myhost的)创建了一个新openweb你(这个你不必知道,你才知道,你会得到一个的SPWeb对象)

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)

阅读全文

相关推荐

最新文章