Professional Documents
Culture Documents
using System;
namespace AddNumbers
class Program
Console.WriteLine(Add<int>(3, 5));
Console.WriteLine(Add<float>(3.5f, 5.6f));
Console.WriteLine(Add<double>(3.5, 5.6));
Console.ReadLine();
static T Add<T>(T a, T b)
In C#, you can create a customized exception by defining a new exception class that derives from the
System.Exception class. The new exception class can include additional properties and methods
to provide more information about the error that occurred.
using System;
namespace CustomExceptionExample
{
class Program
try
if (age < 0)
Console.WriteLine(ex.Message);
Console.ReadLine();
}
Employee pay roll
using System;
this.id = id;
this.name = name;
this.salary = salary;
public int Id
set { id = value; }
return "ID: " + id + ", Name: " + name + ", Salary: " + salary;
public Manager(int id, string name, double salary, double bonus) : base(id, name, salary)
this.bonus = bonus;
{
return base.ToString() + ", Bonus: " + bonus;
class Program
Console.WriteLine(e1);
Console.WriteLine(e2);
Console.WriteLine(m1);
Console.WriteLine(m2);
Console.WriteLine(total);
Console.ReadKey();