locked
Mejor manera de devolver Boolean e Int en una función RRS feed

  • Question


  • Buenas, camaradas, me preguntaba: ¿cuál es la mejor manera de devolver un Boolean e un Int a través de una función en C#?

    ¿Acaso pasandro un String con los dos datos delimitados quizá por una coma y luego parsear la String?

    Ejemplo: "false,22"

    ¡Saludos y gracias por leer!
    • Moved by CoolDadTx Tuesday, June 11, 2013 7:58 PM Wrong locale
    Sunday, June 9, 2013 11:50 PM

Answers

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace ConsoleApplication1
    {
        class Program
        {
            struct returnValue
            {
                public int a;
                public Boolean b;
            }
            static void Main(string[] args)
            {
                returnValue results1 = method1();
                int a = 0;
                Boolean b = false;
                method2(out a, out b);
            }
            static returnValue method1()
            {
                returnValue results = new returnValue();
                results.a = 1;
                results.b = false;
                return results;
            }
            static void method2(out int a, out Boolean b)
            {
                a = 1;
                b = false;
            }
        }
    }

    • Edited by Joel Engineer Monday, June 10, 2013 7:46 AM
    • Marked as answer by pupallone Wednesday, June 12, 2013 12:25 AM
    Monday, June 10, 2013 7:44 AM

All replies

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace ConsoleApplication1
    {
        class Program
        {
            struct returnValue
            {
                public int a;
                public Boolean b;
            }
            static void Main(string[] args)
            {
                returnValue results1 = method1();
                int a = 0;
                Boolean b = false;
                method2(out a, out b);
            }
            static returnValue method1()
            {
                returnValue results = new returnValue();
                results.a = 1;
                results.b = false;
                return results;
            }
            static void method2(out int a, out Boolean b)
            {
                a = 1;
                b = false;
            }
        }
    }

    • Edited by Joel Engineer Monday, June 10, 2013 7:46 AM
    • Marked as answer by pupallone Wednesday, June 12, 2013 12:25 AM
    Monday, June 10, 2013 7:44 AM
  • ¿Es mejor qué usar una regrasar una Tupla <Boolean, int>? y luego con Tupla.Item1 se obtiene el Bool y con .Item2 el int.

    ¡Saludos y gracias por responder!

    Tuesday, June 11, 2013 7:46 PM
  • No sé que pasó, este post parece un duplicado de este otro:

    http://social.msdn.microsoft.com/Forums/es-ES/vcses/thread/b5f0f591-944a-4171-8a35-6b28b6973de5

    Tuesday, June 11, 2013 7:47 PM
  • This is the English forums.  Questions must be posted in English.  Alternatively you can post questions in the forums appropriate for your locale.
    Tuesday, June 11, 2013 7:57 PM