public class test1 { SumHelper Helper = new SumHelper(); public void test() { List<int> theList = new List<int> { 1, 2, 3, 4 }; int result = Helper.Sum(theList); } } public class test2 { SumHelper Helper = new SumHelper(); public void test() { List<int> theList = new List<int> { 7,8,9,10 }; int result = Helper.Sum(theList); } } public class SumHelper { public int Sum(List<int> theList) { int total = 0; foreach (int item in theList) { total += item; } return total; } }An alternative (suggested by Tim) is to have a helper class with a static method
public class test1 { public void test() { List<int> theList = new List<int> { 1, 2, 3, 4 }; int result = SumHelper.Sum(theList); } } public class test2 { public void test() { List<int> theList = new List<int> { 7,8,9,10 }; int result = SumHelper.Sum(theList); } } public class SumHelper // the class should be static if all of its methods are static { public static int Sum(List<int> theList) { int total = 0; foreach (int item in theList) { total += item; } return total; } }