"指针与QUOT;在VB.NET中? [英] "Pointers" in VB.NET?

查看:88
本文介绍了"指针与QUOT;在VB.NET中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以通过

重载构造函数将String的引用传递给表单。


Public Sub New(ByRef strDX As String)

MyBase.New()


InitializeComponent()


结束子


无论如何设置一个本地值来指向那个

的内存地址,这样当我对这个表单进行更改时,

引用的字符串被修改回来在呼叫表格?或者

我是否已隐式设置公共价值或财产或

从活动表格调用调用表格上的函数

来更新值?谢谢。


Sean

I know I can pass a reference to a String into a Form by
overloading the Constructor.

Public Sub New(ByRef strDX As String)
MyBase.New()

InitializeComponent()

End Sub

Is there anyway to set a local value to point to that
memory address so that as I make changes on this form, the
referenced string is modified back on the calling form? Or
do I have implicitly set a public value or property or
call a function on the calling form from the active form
to update the value? Thanks.

Sean

推荐答案

" Sean" <一个******* @ discussions.microsoft.com> schrieb
"Sean" <an*******@discussions.microsoft.com> schrieb
我知道我可以通过重载构造函数将String的引用传递给一个Form。

Public Sub New(ByRef strDX As String)
MyBase.New()

InitializeComponent()

结束子

无论如何都设置一个本地值来指向
内存地址,以便在我对此表单进行更改时,
引用的字符串会在调用表单上修改回来吗?或者我是否已隐式设置公共值或属性,或者从活动表单调用调用表单上的函数来更新值?谢谢。
I know I can pass a reference to a String into a Form by
overloading the Constructor.

Public Sub New(ByRef strDX As String)
MyBase.New()

InitializeComponent()

End Sub

Is there anyway to set a local value to point to that
memory address so that as I make changes on this form, the
referenced string is modified back on the calling form? Or
do I have implicitly set a public value or property or
call a function on the calling form from the active form
to update the value? Thanks.



由于字符串是不可变的,因此无法修改字符串本身。如果

将字符串变量传递给构造函数,则可以将引用

存储到局部变量或类的字段中的字符串中。你不能

存储对传递的字符串变量的引用,既不是本地也不是

字段。


你可以创建包含字符串变量的类,并将类的实例传递给构造函数。可以存储对象引用。由于

调用者和Form指向同一个对象,因此可以从两个位置看到对象中对

字符串字段所做的修改。

出于兴趣:你想要完成什么?


-

Armin

<一个rel =nofollowhref =http://www.plig.net/nnq/nquote.html\"target =_ blank> http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


The string itself can not be modified because strings are "immutable". If
you pass a string variable to the constructor, you can store the reference
to the string in a local variable or in a field of the class. You can not
store the reference to the passed string variable, neither locally nor as a
field.

You can create a class containing a string variable and pass an instance of
the class to the constructor. The object reference can be stored. As the
caller and the Form point to the same object, modifications made to the
string field within the object are visible from both locations.

Out of interest: What are you trying to accomplish?

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


首先,字符串在VB.NET中是不可变的(不能更改)。

其次,你的帖子是对我来说是胡言乱语(我无法理解你)。


没有罪行意味着。


问候 - OHM

肖恩写道:
Firstly, strings are immutable in VB.NET ( cannot be changed ).
Secondly, your post is gibberish to me ( I cannot understand you).

No Offence meant.

Regards - OHM
Sean wrote:
我知道我可以通过重载构造函数将String的引用传递给一个Form。

Public Sub New(ByRef strDX As String)< b r> MyBase.New()

InitializeComponent()

End Sub

无论如何设置一个本地值来指向
内存地址,以便在我对此表单进行更改时,
引用的字符串会在调用表单上修改回来吗?或者我是否已隐式设置公共值或属性,或者从活动表单调用调用表单上的函数来更新值?谢谢。

肖恩
I know I can pass a reference to a String into a Form by
overloading the Constructor.

Public Sub New(ByRef strDX As String)
MyBase.New()

InitializeComponent()

End Sub

Is there anyway to set a local value to point to that
memory address so that as I make changes on this form, the
referenced string is modified back on the calling form? Or
do I have implicitly set a public value or property or
call a function on the calling form from the active form
to update the value? Thanks.

Sean




-

最诚挚的问候 - OHM


O_H_M {at} BTInternet {dot} com



--
Best Regards - OHM

O_H_M{at}BTInternet{dot}com


*" Sean" <一个******* @ discussions.microsoft.com> scripsit:
* "Sean" <an*******@discussions.microsoft.com> scripsit:
我知道我可以通过重载构造函数将String的引用传递给一个Form。

Public Sub New(ByRef strDX As String)
MyBase.New()

InitializeComponent()

结束子

无论如何设置本地值指向
内存地址,以便在我对此表单进行更改时,
引用的字符串会在调用表单上修改回来吗?或者我是否已隐式设置公共值或属性,或者从活动表单调用调用表单上的函数来更新值?谢谢。
I know I can pass a reference to a String into a Form by
overloading the Constructor.

Public Sub New(ByRef strDX As String)
MyBase.New()

InitializeComponent()

End Sub

Is there anyway to set a local value to point to that
memory address so that as I make changes on this form, the
referenced string is modified back on the calling form? Or
do I have implicitly set a public value or property or
call a function on the calling form from the active form
to update the value? Thanks.




字符串在.NET中是不可变的,如果没有

(隐含地)创建新字符串,则无法更改它们的值。


您可以将引用传递给类的实例wrap。字符串

类。快速和肮脏:


\\\

Public Class MyString

Public Value As String

结束班级

///


\\\

Dim m As New MyString()

m.Value =" Foo"

Dim x As New Foo(m)

///


\\\

Public Sub New(ByVal m As MyString)

m.Value =" Bla"

结束Sub

///


-

Herfried K. Wagner [MVP]

< http://www.mvps.org/dotnet>



Strings are immutable in .NET, you cannot change their value without
(implicitly) creating a new string.

You can pass a reference to an instance of a class "wrapping" the string
class. Quick and Dirty:

\\\
Public Class MyString
Public Value As String
End Class
///

\\\
Dim m As New MyString()
m.Value = "Foo"
Dim x As New Foo(m)
///

\\\
Public Sub New(ByVal m As MyString)
m.Value = "Bla"
End Sub
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


这篇关于&QUOT;指针与QUOT;在VB.NET中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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