-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6.2declaringmethod.cs
46 lines (39 loc) · 1.11 KB
/
6.2declaringmethod.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
/*
1. You can define multiple functions within a class.
2. If you are using return data type instead of void, then must return appropriate value with return keyword.
*/
using System;
namespace Declaring_Method
{
class Program
{
string name, city;
int age;
// Creating method for accepting details
public void acceptdetails()
{
Console.Write("\nEnter your name:\t");
name = Console.ReadLine();
Console.Write("\nEnter Your City:\t");
city = Console.ReadLine();
Console.Write("\nEnter your age:\t\t");
age = Convert.ToInt32(Console.ReadLine());
}
// Creating method for printing details
public void printdetails()
{
Console.Write("\n\n===================");
Console.Write("\nName:\t" + name);
Console.Write("\nCity:\t" + city);
Console.Write("\nAge:\t" + age);
Console.Write("\n===================\n");
}
static void Main(string[] args)
{
Program p = new Program();
p.acceptdetails();
p.printdetails();
Console.ReadLine();
}
}
}