24# Array of Objects Object Oriented Programming
using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Employee[] employees = new Employee[5];
employees[0] = new Employee("David", "Solutions", "SDPT",
"Tutorialist", 1000);
employees[1] = new Employee("Alenere", "Solution", "Sdpt", "Tutorial",
100);
employees[0].introduceSelf();
employees[1].introduceSelf();
Console.WriteLine(employees[0].firstName);
Console.WriteLine(employees[1].firstName);
}
}
class Employee
{
public string firstName { get; set; }
public string middleName { get; set; }
public string lastName { get; set; }
public string position { get; set; }
public double salary { get; set; }
public Employee(string firstName, string middleName, string lastName,
string position, double salary)
{
this.firstName = firstName;
this.middleName = middleName;
this.lastName = lastName;
this.position = position;
this.salary = salary;
}
public void introduceSelf()
{
Console.WriteLine("I'am " + firstName +" "+ middleName +" "+ lastName);
}
}
}
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||
using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Employee[] employees = new Employee[5];
employees[0] = new Employee("David", "Solutions", "SDPT",
"Tutorialist", 1000);
employees[1] = new Employee("Alenere", "Solution", "Sdpt", "Tutorial",
100);
employees[2] = new Employee("David", "Solutions", "SDPT",
"Tutorialist", 1000);
employees[3] = new Employee("David", "Solutions", "SDPT",
"Tutorialist", 1000);
employees[4] = new Employee("David", "Solutions", "SDPT",
"Tutorialist", 1000);
foreach (Employee employee in employees)
{
employee.introduceSelf();
}
}
}
class Employee
{
public string firstName { get; set; }
public string middleName { get; set; }
public string lastName { get; set; }
public string position { get; set; }
public double salary { get; set; }
public Employee(string firstName, string middleName, string lastName,
string position, double salary)
{
this.firstName = firstName;
this.middleName = middleName;
this.lastName = lastName;
this.position = position;
this.salary = salary;
}
public void introduceSelf()
{
Console.WriteLine("I'am " + firstName +" "+ middleName +" "+ lastName);
}
}
}
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||
using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Animal[] animals = new Animal[5];
animals[0] = new Pig();
animals[1] = new Dog();
animals[2] = new Dog();
animals[3] = new Pig();
animals[4] = new Pig();
for (int i = 0; i < animals.Length; i++)
{
animals[i].makeSound();
}
}
}
abstract class Animal
{
public abstract void makeSound();
}
class Pig : Animal
{
public override void makeSound()
{
Console.WriteLine("Oink, oink");
}
}
class Dog : Animal
{
public override void makeSound()
{
Console.WriteLine("Arf, arf");
}
}
}
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||
using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Dog[] dogs = new Dog[5];
dogs[0] = new Dog();
dogs[1] = new Dog();
dogs[2] = new Dog();
dogs[3] = new Dog();
dogs[4] = new Dog();
for (int i = 0; i < dogs.Length; i++)
{
dogs[i].makeSound();
}
}
}
abstract class Animal
{
public abstract void makeSound();
}
class Pig : Animal
{
public override void makeSound()
{
Console.WriteLine("Oink, oink");
}
}
class Dog : Animal
{
public override void makeSound()
{
Console.WriteLine("Arf, arf");
}
public void dig()
{
Console.WriteLine("Digging");
}
}
}
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||
using System;
namespace darklter
{
class Program
{
static void Main(string[] args)
{
Console.Write("Student Count : ");
int count = Convert.ToInt32(Console.ReadLine());
Student[] students = new Student[count];
for (int i = 0; i < students.Length; i++)
{
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Student #" + (i + 1));
Console.Write("First Name : ");
string firstName = Console.ReadLine();
Console.Write("Last Name : ");
string lastName = Console.ReadLine();
Console.Write("Course : ");
string course = Console.ReadLine();
Console.Write("Year : ");
int year = Convert.ToInt32(Console.ReadLine());
Console.Write("Section : ");
char section = Convert.ToChar(Console.ReadLine());
students[i] = new Student(firstName, lastName, course, year,
section);
}
foreach(Student student in students)
{
student.introduceSelf();
}
}
}
class Student
{
public string firstName { get; set; }
public string lastName { get; set; }
public string course { get; set; }
public int year { get; set; }
public char section { get; set; }
public Student(string firstName, string lastName, string course, int year,
char section)
{
this.firstName = firstName;
this.lastName = lastName;
this.course = course;
this.year = year;
this.section = section;
}
public void introduceSelf()
{
Console.WriteLine();
Console.WriteLine("Full Name : " + lastName + ", " + firstName);
Console.WriteLine("Cr./Yr./Sec. : " + course + " - " + year + section);
Console.WriteLine();
}
}
}