forum

Home / DeveloperSection / Forums / How to implement nested for loop into Linq?

How to implement nested for loop into Linq?

Manoj Bhatt 2143 23-Dec-2013

How to convert following nested for loop into linq: 

    public string MX()                                                               
    {
        string[] names = { "ali", "reza", "john" };
        string[] roles = { "admin", "user" };
        List<string> result = new List<string>();
        foreach (string username in names)
        {
            foreach (string rolename in roles)
            {
                if (IsUserInRole(username, rolename))
                {
                    result.Add(username + " : " + rolename);
                }
            }
        }
        return string.Join("<br>" ,result);
    }
    public bool IsUserInRole(string username, string rolename)
    {
        //code
        return true;
    }

Updated on 23-Dec-2013

Can you answer this question?


Answer

1 Answers

Liked By