[IronPython] Passing a reference to a string

Martin Maly Martin.Maly at microsoft.com
Tue Jun 19 19:18:30 CEST 2007


The output value of the ref parameter will be returned in the return value:

r.cs:

public class C{
    public static string M(ref string s) {
        string old = s;
        s = "new string";
        return old;
    }
}

D:\Merlin1\Main\Bin\Debug>csc /t:library r.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.


D:\Merlin1\Main\Bin\Debug>ipy.exe
IronPython console: IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.832
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import clr
>>> clr.AddReference("r.dll")
>>> import C
>>> C.M("old string")
('old string', 'new string')
>>>


-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of John Barham
Sent: Tuesday, June 19, 2007 10:10 AM
To: users at lists.ironpython.com
Subject: [IronPython] Passing a reference to a string

I'm trying to call a C# method from IP that takes a reference to a
string as one of its parameters.  I'm passing it a System.String()
object, but the string is not changed after I call the method.  I know
that CPython (and presumably IP) strings are immutable so how do I get
C# to change the string object that I pass in?

Thanks,

  John
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list