-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods.cs
59 lines (48 loc) · 1.54 KB
/
methods.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
namespace MethodDemo
{
class Program
{
// Main method - entry point of the program
static void Main(string[] args)
{
// Calling a method without parameters
Greet();
// Calling a method with parameters
int a = 5;
int b = 10;
int sum = Add(a, b);
Console.WriteLine($"Sum of {a} and {b} is: {sum}");
// Calling an overloaded method
double x = 5.5;
double y = 10.3;
double sumDouble = Add(x, y);
Console.WriteLine($"Sum of {x} and {y} is: {sumDouble}");
// Calling a method with a return value
double radius = 3.5;
double area = CalculateCircleArea(radius);
Console.WriteLine($"Area of circle with radius {radius} is: {area}");
}
// Method without parameters and return type
static void Greet()
{
Console.WriteLine("Hello, welcome to the method demonstration!");
}
// Method with parameters and return type
static int Add(int num1, int num2)
{
return num1 + num2;
}
// Overloaded method - same name but different parameters
static double Add(double num1, double num2)
{
return num1 + num2;
}
// Method with a return value
static double CalculateCircleArea(double radius)
{
const double Pi = 3.14159;
return Pi * radius * radius;
}
}
}