Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main ( string [] args )
- {
- House house = new House ( ConsoleColor.DarkGreen, "ul Kukueva", 2 );
- house.FillHouse ( new Tenant ( "Sergei", 20 ) );
- house.FillHouse (
- new Tenant ( "Roma", 20 ),
- new Tenant ( "Wasya", 25 )
- );
- foreach ( Tenant t in house.Tenants )
- {
- Console.WriteLine (t.Name);
- }
- }
- }
- class House
- {
- ConsoleColor HouseColor;
- string Adress;
- int MaxTenants;
- public Tenant [] Tenants;
- public bool IsFull = false;
- public House ( ConsoleColor col, string adr, int max )
- {
- HouseColor = col;
- Adress = adr;
- MaxTenants = max;
- Tenants = new Tenant [max];
- }
- public void ShowAdress ()
- {
- ConsoleColor defaultColor = Console.ForegroundColor;
- Console.ForegroundColor = HouseColor;
- Console.WriteLine ( Adress );
- Console.ForegroundColor = defaultColor;
- }
- public static bool FindTenant ( Tenant ten )
- {
- return ten!=null;
- }
- Predicate<Tenant> findTenant = FindTenant;
- public void FillHouse ( params Tenant [] tenant )
- {
- int lastTenantID = Array.FindLastIndex ( Tenants, findTenant );
- lastTenantID++;
- for ( int i = 0 ; i < tenant.Length ; i++ )
- {
- if ( lastTenantID < Tenants.Length )
- {
- Tenants [lastTenantID] = tenant [i];
- lastTenantID++;
- }
- else
- break;
- }
- }
- }
- class Tenant
- {
- public string Name;
- byte Age;
- public Tenant ( string name, byte age )
- {
- Name = name;
- Age = age;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment