How to return two values from single methods and set two parent class property calling function 1 time?

Learning-Overthinker-Confused

I have class like below:

public class Employee
    {
        public int EmployeeId { get; set; }
        public string Name { get; set; }
        public bool performance { get; set; }
        public List<Skills> Skills { get; set; }
    }

 public class Skills
    {
        public int Id { get; set; }
        public string skills { get; set; }
        public int Rate { get; set; }
        public int statistics { get; set; }
    }

I have 2 static methods in which 1st static is responsible to just add list of skills. Now for each employee I want to set performance property value which 2nd static method will throw along with list of skills.

I have some logics through which i know that when to return false to performance properties and when to set Rate and Statictics to 0 but the only thing I am not getting is how to return list of skills and associated true or false value without being calling my 2nd static method twice.

Code:

public static List<Employee> ReturnEmployeeList(List<EmployeesModel> employeesModel)
        {
            var list = new List<Employee>();
            foreach (var item in employeesModel)
            {
                list.Add
                          (
                               new Employee
                               {
                                   EmployeeId = item.EmployeeId,
                                   Version = item.Name,
                                   performance=????, // i want to set this value based on value return by 2nd static method
                                   Skills = ReturnSkillList(item.SkillModels)
                               }
                          );
            }

            return list;
        }


  private static List<Skills> ReturnSkillList(List<SkillModels> skillModel)
        {
            var list = new List<Skills>();
            //Here  i have some logic in which i know when to set Rate and statictics to 0 and return false for performance properties
            return list;
        }
Maor Veitsman

I have a feeling that if you would show the logic behind your code it would be possible to refactor it to a state in which a multi valued return type would not be needed - but I'll answer assuming that this is not relevant.

Three possibilities come to mind, none of which is very pretty in my opinion:

  • out variable:

    bool performance;
    Skills = ReturnSkillList(item.SkillModels, out performance);
    

    and the function signature is:

     private static List<Skills> ReturnSkillList(List<SkillModels> skillModel, out bool perf)
    
  • Tuple:

    Tuple<List<Skills, bool> temp = ReturnSkillList(item.SkillModels, out performance);
    Skills = temp.Item1;
    performance = temp.Item2;
    

    and the function signature is:

     private static Tuple<List<Skills>, bool> ReturnSkillList(List<SkillModels> skillModel, out bool perf)
    
  • Dedicated class: Create a simple class with the two relevant properties.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to return two variables from a python function and access its values without calling it two times?

From Dev

How to return two values from a function in C++?

From Dev

How to return two values from a function in C++?

From Dev

How to pass two values from one function to another in the same class?

From Dev

JavaScript: How do I return two values from a function and call those two variables in another function?

From Dev

Calling two Model functions from a single Controller function in Codeigniter

From Dev

How to return values from two columns?

From Dev

How to return two values from PostgreSQL subquery?

From Dev

How to put two values from a single line into two variables in bash?

From Dev

How to set two property value using groovy in the same time from a text file

From Dev

return two values in clips function

From Dev

return two values in clips function

From Dev

How return value from two nested jquery methods?

From Dev

Calling return of parent function from the completion handler

From Dev

Winforms Tag property with two values at the same time

From Dev

how to return two values in one function without using struct?

From Dev

Return two Variables from function

From Dev

How to select values from two table in a single query

From Dev

how to take two values from single button using query string

From Dev

How to add values from two buttons to single inputbox?

From Dev

How to add two values from range slider to form a single value

From Dev

How to return Multiple List<> values from a single function?

From Dev

Cannot set Parent property from child class

From Dev

How to return a single value from a function class into foreach loop

From Dev

How can I return two values from an AJAX query to javascript?

From Dev

How to Return two non-consecutive Index Values from an Array

From Dev

How to return column values from two different tables?

From Dev

How to Return two non-consecutive Index Values from an Array

From Dev

How to return two separate values from an AJAX request?

Related Related

  1. 1

    How to return two variables from a python function and access its values without calling it two times?

  2. 2

    How to return two values from a function in C++?

  3. 3

    How to return two values from a function in C++?

  4. 4

    How to pass two values from one function to another in the same class?

  5. 5

    JavaScript: How do I return two values from a function and call those two variables in another function?

  6. 6

    Calling two Model functions from a single Controller function in Codeigniter

  7. 7

    How to return values from two columns?

  8. 8

    How to return two values from PostgreSQL subquery?

  9. 9

    How to put two values from a single line into two variables in bash?

  10. 10

    How to set two property value using groovy in the same time from a text file

  11. 11

    return two values in clips function

  12. 12

    return two values in clips function

  13. 13

    How return value from two nested jquery methods?

  14. 14

    Calling return of parent function from the completion handler

  15. 15

    Winforms Tag property with two values at the same time

  16. 16

    how to return two values in one function without using struct?

  17. 17

    Return two Variables from function

  18. 18

    How to select values from two table in a single query

  19. 19

    how to take two values from single button using query string

  20. 20

    How to add values from two buttons to single inputbox?

  21. 21

    How to add two values from range slider to form a single value

  22. 22

    How to return Multiple List<> values from a single function?

  23. 23

    Cannot set Parent property from child class

  24. 24

    How to return a single value from a function class into foreach loop

  25. 25

    How can I return two values from an AJAX query to javascript?

  26. 26

    How to Return two non-consecutive Index Values from an Array

  27. 27

    How to return column values from two different tables?

  28. 28

    How to Return two non-consecutive Index Values from an Array

  29. 29

    How to return two separate values from an AJAX request?

HotTag

Archive