Storing a reference to a string

M

Matt Burland

I was wondering what the correct way to do this is, in C++ I'd just use a
string* :

public class A
{
private string myString // I actually want to keep a reference, but
I'm not sure of the syntax
.....
public A(ref string aString)
{
// This method has a reference to aString - Any changes to aString here will
be passed back to the original string
myString = aString // this will copy the string, but I want to be able
to store the reference to the string instead
}
.....
public void ChangeString()
{
myString = "Hello"; // I'd like this to change the original string that
was passed to the constructor
}

cheers
 

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

Top