foreach (var item in Enumerable.Range(0, 128))
{
Console.WriteLine(item);
}
IEnumerator<int> enumerator = Enumerable.Range(0, 128).GetEnumerator();
try
{
while (enumerator.MoveNext())
{
int item = enumerator.Current;
Console.WriteLine(item);
}
}
finally
{
if (enumerator != null)
{
enumerator.Dispose();
}
}
var nums = new[] { 100, 3, 102, 7, 1, 9, 12 };
var max = default(int?);
var min = default(int?);
var avg = 0.0;
var avgCount = 0;
foreach (var number in nums)
{
if (min == null)
{
min = number;
}
else if (max == null)
{
max = number;
if (max < min)
{
max = min;
min = number;
}
}
else if (number < min)
{
avg = ((avg * avgCount) + min.Value) / ++avgCount;
min = number;
}
else if (number > max)
{
avg = ((avg * avgCount) + max.Value) / ++avgCount;
max = number;
}
else
{
avg = ((avg * avgCount) + number) / ++avgCount;
}
}