convert feet to metres in csharp

To convert feet to metres in C#, you can use the following formula:

main.cs
double metres = feet * 0.3048;
31 chars
2 lines

where feet is the length in feet that you want to convert and metres is the equivalent length in metres.

Here's an example method that takes a length in feet and returns the equivalent length in metres:

main.cs
public static double ConvertFeetToMetres(double feet)
{
    double metres = feet * 0.3048;
    return metres;
}
112 chars
6 lines

You can call this method with a value in feet to get the equivalent value in metres, like this:

main.cs
double feet = 6.5;
double metres = ConvertFeetToMetres(feet);
Console.WriteLine("{0} feet is {1:F2} metres", feet, metres);
124 chars
4 lines

This would output:

main.cs
6.5 feet is 1.98 metres
24 chars
2 lines

gistlibby LogSnag