using System.Collections.Generic;
private static List<int> GetListOfIntegersFromOneToTen()
return Enumerable.Range(1, 10).ToList();
private static List<int> GetOddNumbersBetweenZeroAndFifty()
return Enumerable.Range(0,50).Where(x => x % 2 != 0).ToList();
private static List<T> AppendList1ToList2<T>(IEnumerable<T> list1, IEnumerable<T> list2)
return list.Concat(list2).ToList();
private static List<decimal> GetSmallestFiveNumbersGreaterThanFive(List<decimal> numbers)
return (from n in numbers
select n).Take(5).ToList();
private static List<string> GetStringStartingOrEndingWithSubstring(List<string> items, string subString)
where i.IndexOf(subString) == 0 || i.EndsWith(subString)
private static List<KeyValuePair<string, string>> GetDepartmentNamesWithFirstEmployee(List<Employee> employees, List<Department> departments)
var query = from d in departments
join e in employees on d.DepartmentId equals e.DepartmentId
orderby e.Lastname, e.Firstname
select new { Employee = e.Lastname + ", " + e.Firstname, Dep = d.Name.ToString()};
List<string> departmentsChecked = new List<string>();
.Where(item => !departmentsChecked.Contains(item.Dep))
.Select(item => { departmentsChecked.Add(item.Dep) ; return new KeyValuePair<string, string>(item.Dep, item.Employee); }).ToList();
private static List<KeyValuePair<string, int>> GetDepartmentNamesWithTotalEmployeeSalary(List<Employee> employees, List<Department> departments)
var query = from d in departments
join e in employees on d.DepartmentId equals e.DepartmentId into joined
from subEmployee in joined.DefaultIfEmpty()
select new { Dep = d.Name.ToString(), Salary = (subEmployee == null ? 0 : subEmployee.Salary) };
return query.GroupBy(item => item.Dep).Select(groupItem => new KeyValuePair<string, int>(groupItem.Key, groupItem.Sum(x => x.Salary))).ToList();
private static List<int> GetFibonacciSegment(int startPosition, int count)
private static int? GetClosestToZero(List<int> numbers)
private static T[] MergeArrays<T>(T[] array1, T[] array2)
private static IEnumerable<string> AlphabetCombinations()
public static void Main()
"------------------------Sample answer".Dump();
GetListOfIntegersFromOneToTen().Dump();
"------------------------Question 1".Dump();
GetOddNumbersBetweenZeroAndFifty().Dump();
"------------------------Question 2".Dump();
"------------------------Question 3".Dump();
GetSmallestFiveNumbersGreaterThanFive(new List<decimal>
5.05M, 1, 2, 3, 4, 5, 5.1M, 6, 6, 5, 8, 9, 10, 13
"------------------------Question 4".Dump();
GetStringStartingOrEndingWithSubstring(new List<string>
"pete13", "ted", "alan12", "john8", "alan", "charlie", "crete", "134", "claudette"
"------------------------Question 5".Dump();
GetDepartmentNamesWithFirstEmployee(Employees, Departments).Dump();
"------------------------Question 6".Dump();
GetDepartmentNamesWithTotalEmployeeSalary(Employees, Departments).Dump();
"------------------------Question 7".Dump();
GetFibonacciSegment(4, 7).Dump();
"------------------------Question 8".Dump();
GetClosestToZero(new List<int>
3, 5, 8, -1, 9, 100, 35, -4, 2, 1
"------------------------Question 9".Dump();
"------------------------Question 10".Dump();
AlphabetCombinations().Dump();
private static List<Employee> Employees = new List<Employee>
Firstname = "Adam", Lastname = "Reynolds", Salary = 300, DepartmentId = 1
Firstname = "Alan", Lastname = "Thomson", Salary = 350, DepartmentId = 1
Firstname = "Pete", Lastname = "Thomson", Salary = 350, DepartmentId = 1
Firstname = "Paul", Lastname = "Jones", Salary = 550, DepartmentId = 1
Firstname = "Alan", Lastname = "Street", Salary = 320, DepartmentId = 2
Firstname = "Martin", Lastname = "Free", Salary = 370, DepartmentId = 2
private static List<Department> Departments = new List<Department>
DepartmentId = 1, Name = "Accounting"
DepartmentId = 2, Name = "Marketing"
DepartmentId = 3, Name = "Catering"