logo CodeStepByStep logo

SwitchPairs

Language/Type: C# List collections
Related Links:

Write a method named SwitchPairs that accepts a generic List of strings as a parameter and switches the order of pairs of values in the array. Your method should swap the order of the first two values, then switch the order of the next two, and so on. For example, if a variable named list stores {"a", "bb", "c", "ddd", "ee", "f", "g"}, then the call of SwitchPairs(list); should switch the first pair ("a", "bb"), the second pair ("c", "ddd") and the third pair ("ee", "f"), to yield this list:

{"bb", "a", "ddd", "c", "ee", "f", "g"}

If there are an odd number of values, the final element is not moved. You may assume that the list is not null and that no element of the array is null.

Type your C# solution code here:


This is a method exercise. Write a C# method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.