调用返回MemoryStream或XmlDocument的函数 [英] call functions that return MemoryStream or XmlDocument

查看:75
本文介绍了调用返回MemoryStream或XmlDocument的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



假设我有以下功能:


公共函数myF1ToStream(...)As System.IO.MemoryStream

。 。 。

Dim ms As New System.IO.MemoryStream(buf)

返回ms

结束功能


公共函数mcF2ToXml(...)作为Xml.XmlDocument

。 。 。

Dim xmlDoc As New Xml.XmlDocument

xmlDoc.Load(ms)

返回xmlDoc

结束函数

当我调用这些函数时,下列哪一行标有

(''?)是必要的?

(我使用vs2003,没有''使用''关键字。)


Dim ms As System.IO.MemoryStream = myF1ToStream(...)

''? ms.Seek(0,System.IO.SeekOrigin.Begin)

。 。 。 ms.ReadByte()。 。 。

''? ms.Close()

''? ms = Nothing


Dim xmlDoc As XmlDocument = mcF2ToXml(...)

。 。 。 myUse(xmlDoc)。 。 。

''? xmlDoc = Nothing


谢谢,


Atara

***通过Developersdex发送 http://www.developersdex.com ***


Suppose I have the following functions:

Public Function myF1ToStream(...) As System.IO.MemoryStream
. . .
Dim ms As New System.IO.MemoryStream(buf)
Return ms
End Function

Public Function mcF2ToXml(. . .) As Xml.XmlDocument
. . .
Dim xmlDoc As New Xml.XmlDocument
xmlDoc.Load(ms)
Return xmlDoc
End Function
When I call these functions, which of the following lines marked with
(''?) is necessary?
(I use vs2003, without ''Using'' keyword. )

Dim ms As System.IO.MemoryStream = myF1ToStream(...)
''? ms.Seek(0, System.IO.SeekOrigin.Begin)
. . . ms.ReadByte() . . .
''? ms.Close()
''? ms = Nothing

Dim xmlDoc As XmlDocument = mcF2ToXml(...)
. . . myUse(xmlDoc) . . .
''? xmlDoc = Nothing

Thanks,

Atara
*** Sent via Developersdex http://www.developersdex.com ***

推荐答案

Atara,


我从来没有在内存流中使用过搜索,我总是从0开始,所以我不会
知道你的情况是否有必要。


将东西设置为零只意味着它删除了引用,所以

你不能直接使用它了。


然而,这并不意味着它不再存在,因此它有点没有意义。

。 />

因为这是经常被问到的,我已经把这小块样品给了

显示它。


拖动对于这个代码中的一个表格粘贴的DataGridView和一个按钮和

运行它。

\\\

Private Sub Form1_Load(ByVal sender As System.Object,_

ByVal e As System.EventArgs)Handles MyBase.Load

Dim dt As New DataTable

Dim dc As New DataColumn(" a",GetType(System.String))

dt.Columns.Add(dc)

dc.Dispose()

dc = Nothing

For i = 1 to 5

Dim dr As DataRow = dt.NewRow

dr.Item( 0)= i.ToString

dt.Rows.Add(博士)

下一页

DataGridView1.DataSource = dt

dt.Dispose()

dt = Nothing


End Sub


Private Sub Button1_Click(ByVal sender As System.Object,_

ByVal e As System.EventArgs)Handles Button1.Click

Dim dt As DataTable = DirectCast(DataGridView1.DataSource,DataTable)

for i = 6 To 10

dr.Item( 0)= i.ToString

dt.Rows.Add(博士)

下一页

结束子

/ //


Cor



" Atara" < at *** @ DD.comschreef in bericht

新闻:OF ************** @ TK2MSFTNGP03.phx.gbl ...
Atara,

I never used the seek in a memorystream, I always start at zero, so I don''t
know if it in your case is necessary.

Setting something to nothing means only that it removes the reference, so
"you" can not direct use it anymore.

However that does not mean that it does not exist anymore, therefore it is a
little bit without sense.

Because it is asked so often, I have made this little piece of sample to
show it.

Drag for this a DataGridView and a Button on a form paste in this code and
run it.
\\\
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Dim dc As New DataColumn("a", GetType(System.String))
dt.Columns.Add(dc)
dc.Dispose()
dc = Nothing
For i = 1 To 5
Dim dr As DataRow = dt.NewRow
dr.Item(0) = i.ToString
dt.Rows.Add(dr)
Next
DataGridView1.DataSource = dt
dt.Dispose()
dt = Nothing

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = DirectCast(DataGridView1.DataSource, DataTable)
For i = 6 To 10
Dim dr As DataRow = dt.NewRow
dr.Item(0) = i.ToString
dt.Rows.Add(dr)
Next
End Sub
///

Cor


"Atara" <At***@DD.comschreef in bericht
news:OF**************@TK2MSFTNGP03.phx.gbl...

>

假设我有以下功能:


公共函数myF1ToStream(...)As System.IO.MemoryStream

。 。 。

Dim ms As New System.IO.MemoryStream(buf)

返回ms

结束功能


公共函数mcF2ToXml(...)作为Xml.XmlDocument

。 。 。

Dim xmlDoc As New Xml.XmlDocument

xmlDoc.Load(ms)

返回xmlDoc

结束函数


当我调用这些函数时,下列哪一行标有

(''?)是必要的?

(我使用vs2003,没有''使用''关键字。)


Dim ms As System.IO.MemoryStream = myF1ToStream(...)

'' ? ms.Seek(0,System.IO.SeekOrigin.Begin)

。 。 。 ms.ReadByte()。 。 。

''? ms.Close()

''? ms = Nothing


Dim xmlDoc As XmlDocument = mcF2ToXml(...)

。 。 。 myUse(xmlDoc)。 。 。

''? xmlDoc = Nothing


谢谢,


Atara


***通过Developersdex发送 http://www.developersdex.com ***
>
Suppose I have the following functions:

Public Function myF1ToStream(...) As System.IO.MemoryStream
. . .
Dim ms As New System.IO.MemoryStream(buf)
Return ms
End Function

Public Function mcF2ToXml(. . .) As Xml.XmlDocument
. . .
Dim xmlDoc As New Xml.XmlDocument
xmlDoc.Load(ms)
Return xmlDoc
End Function
When I call these functions, which of the following lines marked with
(''?) is necessary?
(I use vs2003, without ''Using'' keyword. )

Dim ms As System.IO.MemoryStream = myF1ToStream(...)
''? ms.Seek(0, System.IO.SeekOrigin.Begin)
. . . ms.ReadByte() . . .
''? ms.Close()
''? ms = Nothing

Dim xmlDoc As XmlDocument = mcF2ToXml(...)
. . . myUse(xmlDoc) . . .
''? xmlDoc = Nothing

Thanks,

Atara
*** Sent via Developersdex http://www.developersdex.com ***





我不明白你的代码示例 - 我是否需要处理

返回的memoryStream和返回的xmlDocument当我完成了

吗?


我从来没有从函数中返回这些类型的示例代码。在

示例代码中,这种类型总是在一个函数中使用(所以我猜

当函数结束时它的内存被收集)


谢谢,


Atara


***通过Developersdex发送 http://www.developersdex.com ***


I did not understand your code sample - do I need to dispose the
returned memoryStream, and the returned xmlDocument when I am done with
them?

I never so a sample code of returning such types from a function. In
sample code, this types are always used within one function (so I guess
that when the function ends its memory is collected)

thanks,

Atara

*** Sent via Developersdex http://www.developersdex.com ***


Atara,


您是否运行过该样本,我已经直接将其置于其中,因为

给出了与此无关的误解。


尝试它,它应该清楚。


你不必在这些情况下设置什么东西或使用

处置方法。很简单,因为它只需要处理时间并且没有任何

效果。


Cor

Atara < at *** @ DD.comschreef in bericht

news:%2 **************** @ TK2MSFTNGP05.phx.gbl ...
Atara,

Did you run the sample, I have put direct the dispose in it, because that
gives mostly the same misunderstandings as the nothing.

Try it and it should becoume clear.

You don''t have to set in these situations something to nothing or to use the
dispose method. Simple because it takes only processing time and has not any
effect.

Cor
"Atara" <At***@DD.comschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...

>


我不明白你的代码示例 - 我是否需要处理

返回memoryStream,当我完成

后返回xmlDocument吗?


我从来没有这样从代码中返回这些类型的示例代码。在

示例代码中,这种类型总是在一个函数中使用(所以我猜

当函数结束时它的内存被收集)


谢谢,


Atara


***通过Developersdex发送 http://www.developersdex.com ***
>

I did not understand your code sample - do I need to dispose the
returned memoryStream, and the returned xmlDocument when I am done with
them?

I never so a sample code of returning such types from a function. In
sample code, this types are always used within one function (so I guess
that when the function ends its memory is collected)

thanks,

Atara

*** Sent via Developersdex http://www.developersdex.com ***


这篇关于调用返回MemoryStream或XmlDocument的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆