Live Traffic Feed

Wednesday, November 12, 2014

How to return multiple value with different data type from function in C#

Leave a Comment
public Tuple<string, int, decimal, string[], DataTable> myFunction()
    {
        string a = "ABC";
        int b = 50;
        decimal c = 45;
        string d = "XYZ";
        string[] ab = new string[2];
        ab[0] = a;
        ab[1] = d;
        DataTable dt = new DataTable();
        return new Tuple<string, int, decimal, string[], DataTable>(a, b, c, ab, dt);

    }



For Calling the Function use below code:

        var res = myFunction();
        string a = res.Item1;
        int b = res.Item2;
        decimal c = res.Item3;
        string[] ab = res.Item4;
        DataTable dt = res.Item5;
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment