Results 1 to 4 of 4

Thread: {RESOLVED} Function output parameter ... ?

  1. #1

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Resolved {RESOLVED} Function output parameter ... ?

    Hello....

    How should i return a value from a function parameter ?

    if in old VB version, i use "byref" in declaring a procedure / function parameter.
    e.g :
    Code:
    private sub Testing(byval str1 as string, byref str2 as string)
       str2 = str1 & "...just testing"
    end sub
    
    private sub command1_click()
       dim tmpStr as string
       
       call Testing("123", tmpstr)
       msgbox(tmpstr)
    end sub
    then the str2 will function as the output parameter.
    How should I do that in C# ? and how should i return the value from that output parameter.... ?

    Thanks,
    Last edited by Wen Lie; May 3rd, 2007 at 11:51 PM. Reason: Problem solved :)
    Regards,
    [-w-]

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Function output parameter ... ?

    The better way would be to have a function that has a return value.
    Code:
    private string Testing(string str1)
    {
      return str1 + ".... just testing";
    }
    You can also use ref keyword to pass value types by reference, but here I would say just use a simple function that returns a value.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Talking Re: Function output parameter ... ?

    Thanks.
    I've tried and it works....
    Regards,
    [-w-]

  4. #4
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667

    Re: {RESOLVED} Function output parameter ... ?

    you could also use out as followed;

    Code:
    	
    	void Button1Click(object sender, EventArgs e)
    		{
    			string outPut;
    			this.Test("THIS IS A TEST", out outPut);
    			MessageBox.Show(outPut);
    			          
    		}
    		
    		void Test(string text, out string text2)
    		{
    			text2 = text + " Hello";	
    		}
    Hope this helps!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width