How to return two objects at the same time in c sharp or Example of Tuple in c sharp

I found ‘Tuple’ to be  a very special , where you want to return two objects in the same function itself. I will explain with the help of below code.

My aim in the below code is to return two objects in the same function. Lets consider those two objects are emp_Permanent and emp_Temp which I need when I call a function. These two objects are of the class Employee.

public Tuple<Employee, Employee> splitEmployee(Employee employee)
        {
          
           
                                                       // here I am splitting my employee objects in to two other objects
                                                       // let’s assume that the new objects are emp_Permanent and emp_Temp
                                                        


            return new Tuple<Employee, Employee>( emp_Permanent, emp_Temp);
        }


Now in your main code, call this function as below.

var splitData =  splitEmployee (employee) ;
           
            emp_Permanent = splitData.Item1;
            emp_Temp = splitData.Item2;

And continue coding.


Thanks.

Comments

Popular posts from this blog

How To Install LEX and YACC in Linux or Ubuntu

How to Create Live Search In Html Using Ajax Ad PhP - Google Live Search / Instant Search Code And Example

Listing/Delisting of an article in to an Assortment in SAP SCM Retail