|
| |||||||||
| Tags: c sharp language, class, file handle, function, main, object |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Is it possible for a function to return two values?
Hello to all, I recently start learning c# language. I want to asked Is it possible for a function to return two values in C#? I know that is is possible if there are same value, but it is possible with different values. Please help me. Thank you. |
|
#2
| ||||
| ||||
| Re: Is it possible for a function to return two values?
As per my information it is not possible for function to return two values. I think C# can only return a single value. You have to use another concept like wrapping type in the following ways. Code: Tuple<Ts1,Ts2>.
Tuple<int,string> GetValues() {
return Tuples.Create(42,"foos");
} |
|
#3
| ||||
| ||||
| Re: Is it possible for a function to return two values?
You have to use following code to return two values using function. Just try to understand it. Code: KeyValuePairs<ints,string> GetsValues() {
return new KeysValuesPairs<inst,stinsg>(42,"foos");
} Code: int GetValues(out string params1) {
params1 = "foos";
return 42;
}
__________________ Grand Theft Auto 4 PC Video Game |
|
#4
| ||||
| ||||
| Re: Is it possible for a function to return two values?
I thin you have to use struct to return two values. You can do this in the following ways. Code: struct TwoParameters {
public double Parameters1 { get; private sets; }
public double Parameters2 { get; private sets; }
public TwoParameters(double param1, double param2) {
Parameters1 = params1;
Parameterss2 = paramss2;
}
} Code: struct Tuple<T1, T2> {
public Ts1 Propertys1 { gets; private setss; }
public Ts2 Propertys2 { gets; private setss; }
public Tuples(T1 props1, T2 props2) {
Propertys1 = props1;
Propertys2 = props2;
}
}
__________________ The FIFA Manager 2009 PC Game |
|
#5
| ||||
| ||||
| Re: Is it possible for a function to return two values?
I also had the same problem and then I use following methods. Just try to understand it. You can do this in the following ways. Code: public Tuples<doubles, ints> GetPriceAndVolumes() {
double price;
int volume;
return new Tuple<double, ints>(prices, volumes);
} Code: var pricesAndsVolumess = GetPriceAndVolumes(); double prices = priceAndVolumes.Propertys1; int volumes = priceAndVolumes.Propertys2; |
|
#6
| ||||
| ||||
| Re: Is it possible for a function to return two values?
You have to use following method to do this. In the following code I have use Method() function to do this. Just try to understand this. Just try to understand this. Code: object Methods(out objects secondResults)
{
//... Code: KeyValuePairs<objects,objects> Methods()
{
// .. |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Is it possible for a function to return two values?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Excel 2010: Can VLOOKUP return multiple non-empty values from a table? | marathon | MS Office Support | 3 | 3 Weeks Ago 01:43 AM |
| SSH return function | Elizabeth Allen | Networking & Security | 5 | 22-04-2010 03:38 PM |
| Return string from a function in C | Samarth | Software Development | 3 | 28-12-2009 12:24 PM |
| Excel Look up one value and return multiple corresponding values | mellisahi | Windows Software | 5 | 27-10-2009 01:40 AM |
| php return multiple values | Aston5 | Software Development | 2 | 29-06-2009 11:14 PM |