using System.Collections.Generic;
public static void Main(string[] args)
var collection1 = new int[] { 1, 2, 3, 5 };
Print(SquareHelper.GetOddSqrtItems(collection1));
Console.WriteLine("\n--------------\n");
var monthCollection1 = new MonthsCollection();
var monthCollection2 = new MonthsCollection();
Print(monthCollection1.GetMonth(10));
Print(monthCollection2.GetMonth(30));
public static void Print<T>(IEnumerable<T> source)
foreach (var item in source)
Console.WriteLine(item?.ToString());
public static class SquareHelper
public static IEnumerable<decimal> GetOddSqrtItems<T>(IEnumerable<T> source) where T : struct
var sourceArray = source.ToArray();
for (int i = 0; i < sourceArray.Length; i++)
var decimalValue = Convert.ToDecimal(sourceArray[i]);
if (decimalValue % 2 != 0)
yield return decimalValue * decimalValue;
public Month(int id, string name, int days)
public int Id { get; set; }
public string Name { get; set; }
public int Days { get; set; }
public override string ToString()
return $"{Id}:{Name}:{Days}";
public class MonthsCollection
private readonly Month[] _month;
public MonthsCollection()
new Month(1, "January", 31),
new Month(2, "February", 28),
new Month(3, "March", 31),
new Month(4, "April", 30),
new Month(6, "June", 30),
new Month(7, "July", 31),
new Month(8, "August", 31),
new Month(9, "September", 30),
new Month(10, "October", 31),
new Month(11, "November", 30),
new Month(12, "December", 31)
public Month[] GetMonth(int indexOrCount)
indexOrCount = indexOrCount == 0 ? 0 : indexOrCount - 1;
return new Month[] { _month[indexOrCount] };
return _month.Where(x => x.Days == indexOrCount).ToArray();