I have method that will receive a string input(with message & mode name) and the method will separate the string input in to two strings(1.message 2.mode name) according to separator. but i need to return this separated two string at a time.please provide me a good way to do this.can i use "out" and return in one method? if yes, please tell me any links to do the out parameter. (or) any good way if you have.
Asked
Active
Viewed 558 times
2 Answers
1
You can use out parameters:
string myMethod(string input, out secondOutput)
{
secondOutput="bla";
return "xyz";
}
you can also use 2 out parameters:
void myMethod(string input, out firstOutput, out secondOutput)
{
firstOutput="bla";
secondOutput = "xyz";
}
Or like others suggested and I think is preferrable most of the time, using an array:
string[] myMethod(string input)
{
return new string[] {firstOutput, secondOutput);
}
If you can tell us what the method is for we might help you choosing the best alternative.

aKzenT
- 7,775
- 2
- 36
- 65
-
yes this answer i need...but problem with receiver side..how can i assign this values to separate strings – Vipin May 16 '11 at 10:25
-
in the case of two out parameters how can i assign?i am calling the method message = [self myMethod]; my method return two put parameters.the how can i set it to – Vipin May 16 '11 at 10:27
-
hi, i wrote a method with out pram -(NSString *)messageDecryption:(NSString *)receivedMessage outParam:(out)messageCondent { messageCondent = [receivedMessage substringFromIndex:2]; return [receivedMessage substringToIndex:1]; } then i passed the parameters NSString *messageCondent; NSString *mode = [myclassobject messageDecryption:message outParam:messageCondent]; – Vipin May 16 '11 at 17:22
0
Why don't you put your 2 string in a Array and return that Array ?

Toncean Cosmin
- 535
- 4
- 19
-
can i use return key word to return a string (message) and out parameter string as mode name. – Vipin May 16 '11 at 10:20
-