Click here to Skip to main content
15,904,156 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends:

I want to have a method that has two input and two different output.

For example:
C#
private int , byte Nameofmethod (string s , int i)
{

}

How should I do that?

Yours
Posted
Updated 9-Mar-12 6:52am
v2

Generally what I consider a better way is to return an object that contains all of the outputs you need. That may be a better solution for what you are looking for, cannot be sure.

C#
private struct ReturnedObject
{
    public ReturnedObject(string variable1, string variable2)
    {
        Variable1 = variable1;
        Variable2 = variable2;
    }
    public string Variable1;
    public string Variable2;
}

private ReturnedObject SomeMethod ()
{
    return new ReturnedObject("first value", "second value");
}


There are exceptions, but C# is an object oriented language and should be using objects. I also prefer objects as arguments, otherwise some calls can become very long. The exeception to this would be where I am doing something like TryParse
 
Share this answer
 
v2
Comments
Mmohmmad 9-Mar-12 11:43am    
Dear Nelson:

Thanks for your reply. would you please provide some code for it?

Yours
Clifford Nelson 9-Mar-12 12:47pm    
Have updated the solution above. Hope this helps.
Mmohmmad 9-Mar-12 14:16pm    
Dear Nelson:

It's awesome. Thanks for your pro. answer.

Yours
Clifford Nelson 9-Mar-12 16:15pm    
Remember you, in addition to voting, which I appreciate, you can also vote.

Glad to be of help
Use parameters with the out keyword:
C#
private void MyMethod(string s, int i, out int intResult, out byte byteResult)
 
Share this answer
 
Comments
Mmohmmad 9-Mar-12 11:15am    
Thanks for your nice respond.

I think I can also use overloaded methods.

Thanks my friend

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900