Skip to content

Commit 797e5a8

Browse files
author
SardarMudassarAliKhan
committed
C# Programming
1 parent 6d42d1e commit 797e5a8

26 files changed

+774
-9
lines changed
File renamed without changes.
File renamed without changes.

CSharp37DelegateUsageInCSharp.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CSharpProgrammingPractice
8+
{
9+
10+
public delegate bool IsPromotable(Employee employee);
11+
public class Employee
12+
{
13+
public int Id { get; set; }
14+
public string Name { get; set; }
15+
public int PhoneNo { get; set; }
16+
public int Salary { get; set; }
17+
18+
public static void EmployeeList(List<Employee> emplist, IsPromotable isPromotable)
19+
{
20+
foreach (Employee emp in emplist)
21+
{
22+
if (isPromotable(emp))
23+
{
24+
Console.WriteLine(emp.Name + ": Promoted");
25+
}
26+
}
27+
}
28+
/* static void Main(string[] args)
29+
{
30+
List<Employee> list = new List<Employee>();
31+
list.Add(new Employee() { Id = 1, Name = "Mudassar", PhoneNo = 45, Salary = 50000 });
32+
list.Add(new Employee() { Id = 2, Name = "Asad", PhoneNo = 46, Salary = 150000 });
33+
list.Add(new Employee() { Id = 3, Name = "Mubashir", PhoneNo = 47, Salary = 160000 });
34+
list.Add(new Employee() { Id = 4, Name = "Muzhar", PhoneNo = 48, Salary = 200000 });
35+
36+
// IsPromotable isPromotable = new IsPromotable(IsPromotableEmployee);
37+
38+
39+
bool IsPromotableEmployee(Employee emp)
40+
{
41+
if (emp.Salary > 50000)
42+
{
43+
return true;
44+
}
45+
else
46+
{
47+
return false;
48+
}
49+
}
50+
51+
Employee employee = new Employee();
52+
Employee.EmployeeList(list, emp => emp.Salary > 50000);
53+
54+
55+
56+
}*/
57+
}
58+
59+
}

CSharp38DelegatesInCsharp.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CSharpProgrammingPractice
8+
{
9+
public delegate void Delegate(String Name);
10+
11+
public class DelegatesInCsharp
12+
{
13+
public void Hello(String Message)
14+
{
15+
Console.WriteLine("Delegate Message "+Message);
16+
}
17+
}
18+
}

CSharp39MultiCastDelegate.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CSharpProgrammingPractice
8+
{
9+
public delegate void MulticastDelegate(out int variable);
10+
public class _39MultiCastDelegate
11+
{
12+
13+
public static void FunctionOne(out int a)
14+
{
15+
Console.WriteLine("Delegate Invoke Function One");
16+
a = 1;
17+
}
18+
public static void FunctionTwo(out int b)
19+
{
20+
Console.WriteLine("Delegate Invoke Function two");
21+
b = 2;
22+
}
23+
public static void FunctionThree(out int c)
24+
{
25+
Console.WriteLine("Delegate Invoke Function three");
26+
c = 3;
27+
}
28+
//public static void Main(String[] args)
29+
//{
30+
// /* MulticastDelegate mcd1, mcd2, mcd3,mcd4;
31+
// mcd2 = new MulticastDelegate(FunctionOne);
32+
// mcd3 = new MulticastDelegate(FunctionTwo);
33+
// mcd4 = new MulticastDelegate(FunctionThree);
34+
// mcd1 = mcd2 + mcd3 - mcd4;
35+
// mcd1();*/
36+
37+
// /*MulticastDelegate multicastDelegate = new MulticastDelegate(FunctionOne);
38+
// multicastDelegate += FunctionTwo;
39+
// multicastDelegate +=FunctionThree;
40+
// multicastDelegate();*/
41+
// MulticastDelegate multicastDelegate = new MulticastDelegate(FunctionOne);
42+
// multicastDelegate += FunctionTwo;
43+
// multicastDelegate += FunctionThree;
44+
// int a = 1;
45+
// multicastDelegate(out a);
46+
// Console.WriteLine("Delegate Output Value =:"+a);
47+
48+
49+
//}
50+
}
51+
52+
53+
}
File renamed without changes.

CSharp40ExceptionInCSharp.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CSharpProgrammingPractice
9+
{
10+
public class _40ExceptionInCSharp
11+
{
12+
//public static void Main()
13+
//{
14+
// StreamReader streamReader = null;
15+
// try
16+
// {
17+
// streamReader = new StreamReader(@"F:\Data1\Data.txt");
18+
// Console.WriteLine(streamReader.ReadToEnd());
19+
// //streamReader.Close();
20+
// }
21+
22+
// catch (FileNotFoundException ex)
23+
// {
24+
// Console.WriteLine("File Not Found = {0}" + ex.Message);
25+
// }
26+
// catch (Exception ex)
27+
// {
28+
// Console.WriteLine(ex.Message);
29+
// //throw;
30+
// }
31+
// finally
32+
// {
33+
// if (streamReader!=null)
34+
// {
35+
// streamReader.Close();
36+
// Console.WriteLine("Resources are Now Free");
37+
// }
38+
39+
// }
40+
//}
41+
}
42+
}

CSharp41InerException.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace CSharpProgrammingPractice
9+
{
10+
public class CSharp41InerException
11+
{
12+
/* public static void Main(String[] args)
13+
{
14+
try
15+
{
16+
try
17+
{
18+
Console.WriteLine("Enter Fisrt Number");
19+
int a = int.Parse(Console.ReadLine());
20+
Console.WriteLine("Enter Second Number");
21+
int b = int.Parse(Console.ReadLine());
22+
int c = a / b;
23+
Console.WriteLine("Result = " + c);
24+
}
25+
catch (Exception ex)
26+
{
27+
String Filepath = @"F:\Data\Log1.txt";
28+
if (File.Exists(Filepath))
29+
{
30+
StreamWriter streamWriter = new StreamWriter(Filepath);
31+
streamWriter.WriteLine(ex.GetType().Name);
32+
streamWriter.WriteLine();
33+
streamWriter.WriteLine(ex.Message);
34+
streamWriter.Close();
35+
}
36+
else
37+
{
38+
throw new FileNotFoundException(Filepath + "File Not Found", ex);
39+
}
40+
}
41+
42+
}
43+
catch (Exception ex)
44+
{
45+
Console.WriteLine("Exception: "+ex.GetType().Name);
46+
if(ex.InnerException!=null)
47+
{
48+
Console.WriteLine("Inner Exception is : = {0}"+ex.InnerException.Message);
49+
Console.WriteLine("Inner Exception is : = {0}"+ex.InnerException.GetType().Name);
50+
}
51+
52+
}
53+
}*/
54+
}
55+
}

CSharp42CustomException.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Runtime.Serialization;
7+
namespace CSharpProgrammingPractice
8+
{
9+
public class _42CustomException:Exception
10+
{
11+
public _42CustomException():base()
12+
{
13+
14+
}
15+
public _42CustomException(String Message):base(Message)
16+
{
17+
Console.WriteLine(Message);
18+
}
19+
public _42CustomException(String Message , Exception InnerException):base(Message,InnerException)
20+
{
21+
22+
}
23+
public _42CustomException(SerializationInfo info, StreamingContext streamingContext):base(info,streamingContext)
24+
{
25+
26+
}
27+
28+
}
29+
[Serializable]
30+
public class Test
31+
{
32+
/*public static void Main(String[] args)
33+
{
34+
throw new _42CustomException("Custom Exception");
35+
}*/
36+
37+
}
38+
}

CSharp43ExceptionAbuse.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CSharpProgrammingPractice
8+
{
9+
public class CSharp43ExceptionAbuse
10+
{
11+
public void FindResult()
12+
{
13+
try
14+
{
15+
Console.WriteLine("Enter First Number");
16+
int numirator;
17+
bool Conversionsuccessfull = Int32.TryParse(Console.ReadLine(), out numirator);
18+
if (Conversionsuccessfull)
19+
{
20+
Console.WriteLine("Enter secont Number");
21+
int Denumirator;
22+
bool ConversionDenumeratorsuccessfull = Int32.TryParse(Console.ReadLine(), out Denumirator);
23+
if (ConversionDenumeratorsuccessfull && Denumirator != 0)
24+
{
25+
int c = numirator / Denumirator;
26+
Console.WriteLine("Result =:" + c);
27+
}
28+
else
29+
{
30+
if (ConversionDenumeratorsuccessfull!=true && Denumirator==0)
31+
{
32+
Console.WriteLine("DeNumenator Cant be Zero rang is = {0},{1}" + Int32.MinValue + "To" + int.MaxValue);
33+
}
34+
}
35+
}
36+
else
37+
{
38+
Console.WriteLine("Numenator Cant be Zero rang is= {0},{1}"+Int32.MinValue +"To"+int.MaxValue);
39+
}
40+
}
41+
catch (Exception ex)
42+
{
43+
Console.WriteLine("Exception caused by:"+ex.GetType().Name);
44+
}
45+
}
46+
}
47+
//public class Test2
48+
//{
49+
// public static void Main(string[] args)
50+
// {
51+
// CSharp43ExceptionAbuse cSharp43ExceptionAbuse = new CSharp43ExceptionAbuse();
52+
// cSharp43ExceptionAbuse.FindResult();
53+
// }
54+
55+
//}
56+
}

CSharp44PreventingExceptionAbouse.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace CSharpProgrammingPractice
8+
{
9+
internal class CSharp44PreventingExceptionAbouse
10+
{
11+
}
12+
//public class Test2
13+
//{
14+
// public static void Main(string[] args)
15+
// {
16+
// CSharp43ExceptionAbuse cSharp43ExceptionAbuse = new CSharp43ExceptionAbuse();
17+
// cSharp43ExceptionAbuse.FindResult();
18+
// }
19+
20+
//}
21+
}

0 commit comments

Comments
 (0)