Need a method to return both a bool and an int

Can anyone show me an example of a method in C# that returns both a Bool and an INT . I think I need to write a method that returns some sort of <List> object but I'm not sure. Any help or direction provided would be most appreciated.
jazzcatoneAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You can return a Class or a Struct which would hold both your values.  Another option would be to pass a variable as "ref" allowing you to change its value within the method and have the original variable also change.
0
 
UnifiedISCommented:
Here's simple class to use:

function Stuff as BOOLINT
         return new BOOLINT(1,99)
end function

Public Class BOOLINT
DIM _TFValue AS boolean
DIM _NumValue AS integer

Public Property TFValue () AS boolean
Get
Return _TFValue
End Get
Set(ByVal value as boolean)
_TFValue = value
End Set
End Property

Public Property NumValue () AS integer
Get
Return _NumValue
End Get
Set(ByVal value as integer)
_NumValue = value
End Set
End Property

Sub New(ByVal TFValue AS boolean, ByVal NumValue AS integer)
_TFValue = TFValue
_NumValue = NumValue

End Sub
End Class
0
 
dimajCommented:
you can have a function that takes an argument that is identified by 'out' keyword.

i.e.

private bool MyBoolIntFunction(out int someNumber) {
   someNumber = 5;
   return true;
}

http://msdn.microsoft.com/en-us/library/t3c3bfhx(v=vs.80).aspx
0
 
Naman GoelSoftware engineer 1Commented:
you can do any thing like above said

private bool Method(out int number)
{
    bool value=false;
    number=10;
    return value;
}

or create a structure or class with values

public class BoolInt
{
public int Integer{get;set;}
public bool Boolean {get;set'}
}

private BoolInt Method()
{
    BoolInt boolInt= new BoolInt();
    boolInt.Integer=10;
    boolInt.Boolean =false;
    return boolInt;
}

or something like this:

private KeyValuePair<int, bool>Method()
{
        return new KeyValuePait<int, bool>(10,false);
}


0
 
jazzcatoneAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.