How to Get the Volume of a Cylinder Using C#

In this tutorial, I will teach you how to get the volume of a cylinder using c#. We all know that the formula for the volume of a cylinder is pi times radius squared times height. So. I made a program that can help you calculate the volume of a cylinder with ease. In order to use this program, you have to put the radius of the base and the height, then click the calculate button to get the result.

Creating Application

Step 1

Open Microsoft Visual Studio 2015 and create a new windows form application for c#. ps1

Step 2

Do the form just like shown below. ps2

Step 3

Double click the calculate button to open the button1_Click event handler and do the following code for calculating the volume of a cylinder.
  2. private void button1_Click(object sender, EventArgs e)
  3. {
  4. //declaring variables
  5. double inp_based = 0;
  6. double inp_height = 0;
  7. double pi = 3.14;
  8. double volume = 0;
  11. //passing the value of a textbox in the variables
  12. inp_based = double.Parse(txtBase.Text);
  13. inp_height = double.Parse(txtHieght.Text);
  15. // Set the formula to get the volume of a cylinder
  16. volume = ((inp_based * inp_based) * inp_height) * pi;
  18. //displaying the result
  19. txtOutput.Text = "The volume of a cylinder is : " + volume.ToString() + " m3";
  20. }
Output Output The complete sourcecode is included. You can download it and run it on your computer. For any questions about this article. You can contact me @ Email – [email protected] Mobile No. – 09305235027 – TNT Or feel free to comment below.

Add new comment