public class Employee
{
//Fields, properties, methods and events, you can write here...
}
using System;
namespace ConsoleApplication1
{
public class Employee
{
int EmpID;
string Name;
string Address;
//Default Constructor
public Employee()
{
EmpID = 0;
Name = "N/A";
Address = "N/A";
}
// Public Properties
public int ID
{
get { return EmpID; }
set { EmpID = value; }
}
public string empName
{
get { return Name; }
set { Name = value; }
}
public string empAddress
{
get { return Address; }
set { Address = value; }
}
// Methods
public void getData()
{
Console.WriteLine("Enter Employee ID");
ID =Convert.ToInt32( Console.ReadLine());
Console.WriteLine("Enter Employee Name");
empName = Console.ReadLine();
Console.WriteLine("Enter Employee Address");
empAddress = Console.ReadLine();
}
public void showData()
{
Console.WriteLine("Employee ID\t"+EmpID);
Console.WriteLine("Employee Name\t" + empName);
Console.WriteLine("Employee Address\t" + empAddress);
}
}
class Program
{
static void Main(string[] args)
{
Employee emp = new Employee();
emp.getData();
emp.showData();
Console.ReadLine();
}
}
}
class CompareDemo
{
public bool CompareType(int x, int y)
{
if (x.Equals(y))
return true;
else
return false;
}
public bool CompareType(string x, string y)
{
if (x.Equals(y))
return true;
else
return false;
}
}
using System;
namespace ConsoleApplication1
{
class CompareDemo<T>
{
public bool CompareType(T x, T y)
{
if (x.Equals(y))
return true;
else
return false;
}
}
class Program
{
static void Main(string[] args)
{
CompareDemo<string> strObj = new CompareDemo<string>();
bool strResult = strObj.CompareType("DEMO", "DEMO");
Console.WriteLine("Generic string compare result:=" + strResult);
CompareDemo<int> intObj = new CompareDemo<int>();
bool intResult = intObj.CompareType(10, 20);
Console.WriteLine("Generic integer compare result:=" + intResult);
Console.ReadLine();
}
}
}
using System;
namespace ConsoleApplication1
{
class GenClass<T, V>
{
T var1;
V var2;
// Constructor has parameters of type T and V.
public GenClass(T o1, V o2)
{
var1 = o1;
var2 = o2;
}
// Show types of T and V.
public void showData()
{
Console.WriteLine("Type of T is " + typeof(T));
Console.WriteLine("Type of V is " + typeof(V));
}
public T getVar1()
{
return var1;
}
public V GetVar2()
{
return var2;
}
}
class Program
{
static void Main(string[] args)
{
GenClass<int, string> genObj =new GenClass<int, string>(25, "WELCOME");
genObj.showData();
int v = genObj.getVar1();
Console.WriteLine("value: " + v);
string str = genObj.GetVar2();
Console.WriteLine("value: " + str);
Console.ReadLine();
}
}
}