Need a method to return both a bool and an int

Posted on 2011-10-05
Last Modified: 2012-05-12
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.
Question by:jazzcatone
    LVL 85

    Accepted Solution

    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.
    LVL 18

    Assisted Solution

    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
    Return _TFValue
    End Get
    Set(ByVal value as boolean)
    _TFValue = value
    End Set
    End Property

    Public Property NumValue () AS integer
    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
    LVL 7

    Assisted Solution

    you can have a function that takes an argument that is identified by 'out' keyword.


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

    Assisted Solution

    by:Naman Goel
    you can do any thing like above said

    private bool Method(out int number)
        bool value=false;
        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.Boolean =false;
        return boolInt;

    or something like this:

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


    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now