To find the area of a trapezoid in C#, use the formula:
main.cs26 chars2 lines
Where b1 and b2 are the lengths of the parallel sides (base1 and base2 in the diagram below), and h is the height of the trapezoid (the perpendicular distance between the parallel sides).
Here's an example C# method that calculates the area of a trapezoid given the lengths of its bases and height:
main.cs134 chars6 linesYou can call this method like this:
main.cs201 chars6 lines
Output:
main.cs56 chars2 lines
gistlibby LogSnag