Микрософт на дух не переношу, однако деньги не пахнут).
Рекрутер прислал образец что спрашивают на панел интервью.
Кому интересно kто больше ошибок/недоделок найдет?:
Complete the implementation of the following code:
Код: Выделить всё
using System;
using System.Collections;
namespace Test
{
enum Title { Miss, Mrs, Mr, Dr, Sir }
class FullName
{
Title title;
string firstName;
string lastName;
public FullName( Title title,
string firstName,
string lastName)
{
this.title = title;
this.firstName = firstName;
this.lastName = lastName;
}
public override int GetHashCode()
{
int hashCode = this.title.GetHashCode();
if (this.firstName != null)
hashCode ^= this.firstName.GetHashCode();
if (this.lastName != null)
hashCode ^= this.lastName.GetHashCode();
return hashCode;
}
public override bool Equals(object obj)
{
if ((obj == null) ||((obj is FullName) == false))
return false;
FullName fullName = obj as FullName;
if (this.title.Equals(fullName.title) == false)
return false;
if (this.firstName.Equals(fullName.firstName) == false)
return false;
if (this.lastName.Equals(fullName.lastName) == false)
return false;
return true;
}
public override string ToString()
{
return this.title.ToString() + " " + this.firstName + " " + this.lastName;
}
public static bool Equals(object obj1, object object2)
{
if (object1 == null)
{
if (object2 == null)
return true;
else
return false;
}
else
return object1.Equals(object2);
}
public static bool operator ==(FullName obj1,
FullName obj2)
{
return Equals (obj1, obj2);
}
public static bool operator !=(FullName obj1,
FullName obj2)
{
return !Equals (obj1, obj2);
}
}
class Person
{
FullName name;
DateTime dob; // Date of birth
string ssn; // Social security number
string dln; // Driver's licence number
public Person(FullName name,
DateTime dob,
string ssn,
string dln)
{
this.name = name;
this.dob = dob;
this.ssn = ssn;
this.dln = dln;
}
public override string ToString()
{
return
"Name: " + name.ToString() +
Environment.NewLine +
"DOB: " + dob.ToShortDateString() +
Environment.NewLine +
"SSN: " + ssn + Environment.NewLine +
"DLN: " + dln.ToString();
}
}
class Program
{
public static void Main()
{
Hashtable people = new Hashtable();
FullName name = new FullName(Title.Mr,
"John", "Doe");
people.Add(name, new Person(name,
new DateTime(1977, 8, 7),
"012-345-6789", "WA1234567890"));
Console.WriteLine(people[name].ToString());
}
}
}