-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2_Indexers_Csharp.cs
84 lines (57 loc) · 1.45 KB
/
2_Indexers_Csharp.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Reflection;
namespace ConsoleApp3
{
class Person
{
public int EmpId { get; set; }
public string EmpName { get; set; }
}
class Company
{
private List<Person> listPersons;
public Company()
{
listPersons = new List<Person>();
listPersons.Add(new Person { EmpId = 1, EmpName = "Awias" }) ;
listPersons.Add(new Person { EmpId = 2, EmpName = "Ali" });
listPersons.Add(new Person { EmpId = 3, EmpName = "Ahmad" });
}
public string this[int empId]
{
get
{
foreach(var per in listPersons)
{
if(per.EmpId == empId)
{
return per.EmpName;
}
}
return null;
}
set
{
foreach (var per in listPersons)
{
if (per.EmpId == empId)
{
per.EmpName = value;
}
}
}
}
}
class Program
{
static void Main()
{
Company ob = new Company();
//ob[3];
Console.WriteLine(ob[1]);
ob[1] = "Talha";
Console.WriteLine(ob[1]);
}
}
}