Table of Contents

You have chosen the right place. We are sure that this **C# Program to Calculate the VARIANCE of a Set of Given Numbers** article will fill all your doubts. Let’s go to the article

## C# Program to Calculate the VARIANCE of a Set of Given Numbers

```
//C# Program to Find the VARIANCE of a set of given numbers.
using System;
using System.Collections.Generic;
class Program
{
private static void Main()
{
List<double> list = new List<double> { 1, 2, 3, 4, 5, 6};
double mean = 0;
double variance = 0;
double sum = 0;
double temp = 0;
int loop = 0;
for (loop = 0; loop < list.Count; loop++)
{
sum += list[loop];
}
mean = sum / (list.Count - 0);
for (loop = 0; loop < list.Count; loop++)
{
temp += Math.Pow((list[loop] - mean), 2);
}
variance=temp / (list.Count - 0);
Console.WriteLine("Mean : " + mean );
Console.WriteLine("Variance: " + variance);
}
}
```

```
Mean : 3.5
Variance: 2.91666666666667
Press any key to continue . . .
```

## Final Words

We hope the **C# Program to Calculate the VARIANCE of a Set of Given Numbers** article will address some of your concerns. Also if you have any doubts please leave a comment in the comment box.