locked
A ref or out argument must be an assignable variable_

    Question

  • hi, I am working with c# application which is converted from vb. I experence an error that is A ref or out argument must be an assignable variable I use (ref this.site.Getxml()); can any one help in this? Thanks in advance.
    Monday, October 19, 2009 10:03 AM

Answers

  • Define a variable for the return from Getxml() and use this variable as the ref argument. 
    • Marked as answer by Harry Zhu Monday, October 26, 2009 2:29 AM
    Monday, October 19, 2009 10:10 AM
  • Spelled out:

      string xml = this.site.GetXml();
      SomeMethod(ref xml);

    Also check if the method is actually changing the passed value.  There is a lot of VB code that uses ByRef unnecessarily, a hold-over from the VB6 days which passed ByRef by default.

    Hans Passant.
    • Marked as answer by Harry Zhu Monday, October 26, 2009 2:29 AM
    Monday, October 19, 2009 12:17 PM
    Moderator

All replies

  • Define a variable for the return from Getxml() and use this variable as the ref argument. 
    • Marked as answer by Harry Zhu Monday, October 26, 2009 2:29 AM
    Monday, October 19, 2009 10:10 AM
  • Spelled out:

      string xml = this.site.GetXml();
      SomeMethod(ref xml);

    Also check if the method is actually changing the passed value.  There is a lot of VB code that uses ByRef unnecessarily, a hold-over from the VB6 days which passed ByRef by default.

    Hans Passant.
    • Marked as answer by Harry Zhu Monday, October 26, 2009 2:29 AM
    Monday, October 19, 2009 12:17 PM
    Moderator