- Klasy Okrag, Trojkat, Prostokat dziedziczące z klasy:
public class Figura
{
public double[] Parametry {get;set;}
public void Rysuj(Graphics gr)
{
g.DrawString("Nie potrafię rysować, gdyż jestem zbyt prosta.",
new Font("Arial", 16), Brushes.Red, parametry[0], parametry[1]);
}
}
- Program własnego pomysłu demonstrujący różnice w efektach pokrywania w klasach potomnych metod zwykłych i wirtualnych poniższej klasy.
public class Wykonawca
{
public void PracaA(string FileName)
{
StringBuilder sb = new StringBuilder();
string[] lines = File.ReadAllLines(FileName);
for (int i = 0; i < lines.Length; i++)
{
sb.Clear();
for (int j = 0; j < lines[i].Length; j++)
{
sb.Append(lines[i][j]);
sb.Append('_');
}
lines[i] = sb.ToString();
}
string FileName2 = FileName.Replace(".", "2.");
File.WriteAllLines(FileName2, lines);
}
public virtual void PracaB()
{
StringBuilder sb = new StringBuilder();
string[] lines = File.ReadAllLines(FileName);
foreach (string s in lines)
{
sb.AppendLine(s);
sb.AppendLine('---------------------------------------------');
}
string FileName2 = FileName.Replace(".", "2.");
File.WriteAllText(FileName2, sb.ToString());
}
}
- Zademonstrować wykorzystanie interfejsu:
public interface IPodatek
{
string Kod { get; set; }
string Nazwa { get; set; }
double Stawka { get; set;}
double Oblicz(double Kwota);
}
na przykładzie dwóch klas implementujących i klasy z metodą o parametrze typu IPodatek.