You are on page 1of 8

DOTNET

Assignment 6

NAME : KACHHADIYA GRISHMABEN MUKESHBHAI


Prn no. : 2020033800099905
E-mail id : mukeshkachhdiya095@gmail.com
Mobile no. : 8128258930
2

Question 1: Delegate for sorting

ANSWER : -

// See https://aka.ms/new-console-template for more information


public class Sort
{
static public void Sorting<T>(List<T> objectlist, Func<T, T, bool> compare)
{
for (int i = 0; i < objectlist.Count - 1; i++)
{
for (int j = i + 1; j < objectlist.Count; j++)
{
if (!compare(objectlist[i], objectlist[j]))
{
T temp = objectlist[i];
objectlist[i] = objectlist[j];
objectlist[j] = temp;
}
}
}
}
}

public enum Designations


{
PO = 1,
Manager = 2,
Seniar_Manager = 3,
Chief_Manager = 4,
Assistant_General_Manager = 5,
Deputy_General_Manager = 6
}
public class Bank
{
public int id { get; set; }
public string name { get; set; }
public int salary { get; set; }
public Designations designations { get; set; }

public Bank(int id, string name, int salary, Designations designations)


{
this.id = id;
this.name = name;
this.salary = salary;
this.designations = designations;
}

public void Info()


{
Console.WriteLine("\n==>Id of Employee : " + id);
Console.WriteLine("==>Name Of Employee : " + name);
2

Console.WriteLine("==>Salary Of Employee : " + salary);


Console.WriteLine("==>Designation of Employee : " + designations.ToString());
}
public static bool CompareDesignations(Bank bank1, Bank bank2)
{
if (bank1.designations <= bank2.designations)
{
return true;
}
else
{
return false;
}
}

public static bool CompareSalary(Bank bank1, Bank bank2)


{
if (bank1.salary <= bank2.salary)
{
return true;
}
else
{
return false;
}
}
}

public class Assignment6_1


{
public static void Main(string[] args)
{
List<Bank> list = new List<Bank>(10);

list.Add(new Bank(1, "Marag", 80000, Designations.PO));


list.Add(new Bank(2, "Neel", 85000, Designations.Seniar_Manager));
list.Add(new Bank(3, "Rudra", 90000, Designations.Deputy_General_Manager));
list.Add(new Bank(4, "Sushil", 70000, Designations.Assistant_General_Manager));
list.Add(new Bank(5, "Arijit", 60000, Designations.Chief_Manager));
list.Add(new Bank(6, "Mukesh", 180000, Designations.Deputy_General_Manager));

Console.WriteLine("**>Information of Employees According to order of their designation : ");

Sort.Sorting<Bank>(list, Bank.CompareDesignations);

foreach (Bank emp in list)


{
emp.Info();
}

Console.WriteLine("\n\n**>Information of Employees According to order of their salary : ");

Sort.Sorting<Bank>(list, Bank.CompareSalary);

foreach (Bank emp in list)


{
emp.Info();
}
}
2

}
OUTPUT : -
2

Question 2: Delegate msg print :

ANSWER : -

// See https://aka.ms/new-console-template for more information

public delegate void writeMsg(string msg);


public class Assignment6_2 {

public static void showMsg(string msg)


{
Console.WriteLine("\n ==>Status of Account : "+msg);
}
public static void Main(String[] args)
{
Console.Write("\n==>Hello, Please Enter Your bank-balance Here : ");
int bal = Convert.ToInt32(Console.ReadLine());

writeMsg Staus = showMsg;

if(bal<0)
{
Staus("You are overdrawn");
}
else if(bal<10)
{
Staus("Your account is very law");
}
2

else if (bal < 100)


{
Staus("Watch your spending Carefully");
}
else
{
Staus("Your have over $100 in your account");
}
}
}

OUTPUT : -
2

Question 3: Delegate with Anonymous Methos :

ANSWER : -

// See https://aka.ms/new-console-template for more information

public class Assignment6_3


{
public static void delegateWithAnonymousMethod()
{
bool positive = new Func<int, bool>(delegate { return 32 > 0; })(0);
new Action<bool>(delegate (bool value) { Console.WriteLine(value); })(positive);
}
public static void delegateWithLamdaExpression()
{
bool positive = new Func<int, bool>(int32 => int32 > 0)(1);
new Action<bool>(value => { Console.WriteLine(value); })(positive);
}
static void Main(string[] args)
{

delegateWithAnonymousMethod();
delegateWithLamdaExpression();
2

var parse = (double x, double y) => (x > y ? x : y);


double z = parse(22.3, 44.5);
Console.WriteLine("\n==>Val of z is : "+z);

}
}

OUTPUT : -

You might also like