-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathProgram.cs
More file actions
198 lines (168 loc) · 8.53 KB
/
Program.cs
File metadata and controls
198 lines (168 loc) · 8.53 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System;
using System.Collections.Generic;
using System.Linq;
namespace Basics
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("**** Constructors ****");
/* default constructor */
Constructor cons2 = new Constructor();
cons2.Display();
Console.WriteLine();
/* parameterized constructor */
Constructor cons1 = new Constructor("Hello World");
cons1.Display();
Console.WriteLine("\n\n----------------------------\n\n");
Console.WriteLine("**** Example of set, get properties ****");
PropertiesExpression props = new PropertiesExpression();
props.Example();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Strings ****");
StringExpression strExp = new StringExpression();
strExp.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Array ****");
Array array = new Array();
array.set1DArray();
array.set2DArray();
array.setJaggedArray();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Indexers ****");
Indexers indexers = new Indexers();
indexers.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Inheritance ****");
Console.WriteLine();
Console.WriteLine("**** Single level inheritance ****");
Teacher teacher = new Teacher();
teacher.SetTeacher("C#", "Masters", 2, "Hari", "Kathmandu", "IT");
teacher.GetTeacher();
Console.WriteLine();
// create 5 objects of Employee class using list
List<Employee> employees = new List<Employee>()
{
new Employee() { id = 1, name = "Suyash", address = "Kathmandu", department = "CSIT" },
new Employee() { id = 2, name = "Sandesh", address= "Bhaktapur", department = "CSIT" },
new Employee() { id = 3, name = "Shreyan", address = "Butwal", department = "CSIT" },
new Employee() { id = 4, name = "Prashanna", address = "Pokhara", department = "CSIT" },
new Employee() { id = 5, name = "Amish", address = "Kathmandu", department = "CSIT" }
};
foreach (var employee in employees)
{
Console.WriteLine($"Id: {employee.id}");
Console.WriteLine($"Name: {employee.name}");
Console.WriteLine($"Address: {employee.address}");
Console.WriteLine($"Department: {employee.department}");
}
// using lambda to sort object and display
var employeesSorted = employees.OrderBy(employee => employee.name);
foreach (var employee in employeesSorted)
{
Console.WriteLine($"Id: {employee.id}");
Console.WriteLine($"Name: {employee.name}");
Console.WriteLine($"Address: {employee.address}");
Console.WriteLine($"Department: {employee.department}");
}
var findEmployee = employees.FindAll(employee => employee.id == 1);
foreach (var employee in findEmployee)
{
Console.WriteLine($"Id: {employee.id}");
Console.WriteLine($"Name: {employee.name}");
Console.WriteLine($"Address: {employee.address}");
Console.WriteLine($"Department: {employee.department}");
}
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Multilevel inheritance ****");
PartTimeTeacher hari = new PartTimeTeacher();
hari.SetPartTimeTeacher(20, "C#", "Masters", 2, "Hari", "Kathmandu", "IT");
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Base keyword ****");
ChildClass childClass = new ChildClass();
childClass.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Method Hiding ****");
MethodHidingChild methodHiding = new MethodHidingChild();
methodHiding.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Structs ****");
Structs str = new Structs();
str.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Enums ****");
Enums en = new Enums();
en.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Abstract class ****");
InheritAbstract inheritAbstract = new InheritAbstract();
inheritAbstract.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Sealed class ****");
SealedExpression sealedExpression = new SealedExpression();
sealedExpression.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Interface ****");
InterfaceExpression inter = new InterfaceExpression();
inter.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Partial class ****");
Partial_class partialClass = new Partial_class(1, 2);
partialClass.PrintItems();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Delegates and Events ****");
Delegates_and_Events delegates = new Delegates_and_Events();
delegates.DelegateMethod();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Collections ****");
Collections collections = new Collections();
collections.List();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Generics ****");
Generics generics = new Generics();
generics.GenericList();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** File handling ****");
FileIO fileIO = new FileIO();
Console.WriteLine("Do you want to read or write the file? (r/w): ");
if (Console.ReadLine() == "w")
fileIO.Write();
else
fileIO.Read();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** PolyMorphism in code extensibility ****");
/* Static polymorphism */
Console.WriteLine("**** Method Overloading ****");
MethodOverloading methodOverriding = new MethodOverloading();
methodOverriding.Add(10, 20);
methodOverriding.Add(10, 20, 30);
methodOverriding.Add(10.5, 20.5);
Console.WriteLine();
/* Dynamic polymorphism */
Console.WriteLine("**** Method Overriding ****");
MethodOverrdingParent methodOverrdingParent = new MethodOverridingChild();
methodOverrdingParent.Display();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** LINQ ****");
Linq_expression linq = new Linq_expression();
linq.Linq();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Lambda expression ****");
Lambda_Expression lambdaExpression = new Lambda_Expression();
lambdaExpression.Lambda();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Exception Handling ****");
ExceptionHandling exceptionHandling = new ExceptionHandling();
exceptionHandling.SetData();
exceptionHandling.Divide();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("**** Asynchronous programming ****");
Asynchronous_Programming async = new Asynchronous_Programming();
async.CallProcess();
Console.WriteLine("\n----------------------------\n\n");
Console.WriteLine("hello there");
Console.ReadKey(); // to hold the console screen
}
}
}