• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

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.
0
jazzcatone
Asked:
jazzcatone
4 Solutions
 
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 GoelCommented:
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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now