-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.9example2.cs
60 lines (52 loc) · 1.06 KB
/
8.9example2.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
59
60
Qu2:Write a program to explain get set accessor.
Example:
using System;
namespace Example2
{
class input
{
private static int num1, num2, result;
public void add()
{
result = num1 + num2;
Console.WriteLine("\n\nAdd = {0}", result);
Console.ReadLine();
}
// Creating property for storing value in num1
public int Number1
{
get
{
return num1;
}
set
{
num1 = value;
}
}
// Creating property for storing value in num2
public int Number2
{
get
{
return num2;
}
set
{
num2 = value;
}
}
}
class Program
{
static void Main(string[] args)
{
input inp = new input();
Console.Write("Enter number 1st:\t");
inp.Number1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter number 2nd:\t");
inp.Number2 = Convert.ToInt32(Console.ReadLine());
inp.add();
}
}
}