Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication3
- {
- class Program
- {
- static void Main(string[] args)
- {
- IEnumerable<String> enu = new String[] {"koko", "kol"};
- enu.IsEmpty();
- enu.MeanLength();
- IEnumerable<float> floatt = new float[] { 2.3f, 4.5f};
- floatt.IsEmpty();
- floatt.Mean();
- IEnumerable<int> intt = new int[] {};
- intt.IsEmpty();
- intt.Mean();
- Console.ReadKey();
- }
- }
- static class Rozszerzajaca
- {
- public static bool IsEmpty(this IEnumerable source)
- {
- if (source != null && source.GetEnumerator().MoveNext())
- {
- Console.WriteLine("IsEmpty: Not Empty!");
- return false;
- }
- else
- {
- Console.WriteLine("IsEmpty: Empty!");
- return true;
- }
- }
- public static void Mean(this IEnumerable<float> source)
- {
- if (source != null && source.GetEnumerator().MoveNext())
- {
- float sum = 0;
- int il = 0;
- foreach (float i in source)
- {
- sum = sum + i;
- il++;
- }
- float res = sum / il;
- Console.WriteLine("Mean: " + res);
- }
- else
- Console.WriteLine("Mean: Empty array!");
- }
- public static void Mean(this IEnumerable<int> source)
- {
- if (source != null && source.GetEnumerator().MoveNext())
- {
- double sum = 0;
- int il = 0;
- foreach (int i in source)
- {
- sum = sum + i;
- il++;
- }
- double res = sum / il;
- Console.WriteLine("Mean: " + res);
- }
- else
- Console.WriteLine("Mean: Empty array!");
- }
- public static void MeanLength(this IEnumerable<string> source)
- {
- if (source != null && source.GetEnumerator().MoveNext())
- {
- double sum = 0;
- int il = 0;
- foreach (var i in source)
- {
- sum = sum + i.Length;
- il++;
- }
- double res = sum / il;
- Console.WriteLine("Mean length: " + res);
- }
- else
- Console.WriteLine("Mean length: Empty array!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement