Inteface
This commit is contained in:
45
Exercises/E42_Interfaces/Exercise_1.cs
Normal file
45
Exercises/E42_Interfaces/Exercise_1.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
namespace Exercises_C_Sharp.E42_Interfaces
|
||||
{
|
||||
//Sie sehen unten drei verschiedene Klassen aus drei Subsystemen Ihrer Firma. Diese verlangt jetzt von Ihnen, dass alle Namen auf der Konsole ausgegeben werden sollen. Schreiben Sie dafür ein Interface und implementieren Sie dieses bei den Klassen.
|
||||
//Vergessen Sie nicht, den Typen dynamic auf den Namen Ihres Interfaces zu ändern.
|
||||
class Exercise_1
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
List<dynamic> NamesList = new(){ new Person("Matteo"), new Customer("Emilia"), new Human("Noah"), new Person("Emma"), new Customer("Finn"), new Human("Hannah"), new Person("Luca"), new Customer("Sophia"), new Human("Leon"), new Person("Mia"), new Customer("Henry"), new Human("Lina"), new Person("Elias"), new Customer("Ella"), new Human("Paul") };
|
||||
|
||||
foreach(var element in NamesList)
|
||||
element.PrintName();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
|
||||
class Person{
|
||||
string _personName;
|
||||
public Person(string name)
|
||||
{
|
||||
_personName = name;
|
||||
}
|
||||
|
||||
}
|
||||
class Customer{
|
||||
string _customerName;
|
||||
public Customer(string name)
|
||||
{
|
||||
_customerName = name;
|
||||
}
|
||||
|
||||
}
|
||||
class Human{
|
||||
string _humanName;
|
||||
public Human(string name)
|
||||
{
|
||||
_humanName = name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
40
Exercises/E42_Interfaces/Exercise_2.cs
Normal file
40
Exercises/E42_Interfaces/Exercise_2.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
namespace Exercises_C_Sharp.E42_Interfaces
|
||||
{
|
||||
//Sie sollen für einen Sondmixer die Klassen Drums, Guitar und Keyboard erstellen. Alle drei sollen von ISound ableiten. Um die Applikation zu testen, geben Sie bei der implementierten Methoden ein zufälliges Byte-Array zurück. Erstellen Sie dann die drei Objekte der jeweiligen Klassen und übergeben diese der Methode MergeSound().
|
||||
|
||||
class Exercise_2
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
}
|
||||
|
||||
public static void MergeSound(List<ISound> sounds)
|
||||
{
|
||||
List<byte> byteList = new();
|
||||
foreach(var element in sounds)
|
||||
{
|
||||
byte[] bytes = element.MakeSound();
|
||||
for(int i = 0; i < bytes.Length; i++)
|
||||
{
|
||||
if(byteList.Count <= i)
|
||||
byteList.Add(bytes[i]);
|
||||
else
|
||||
byteList[i] = (byte)(byteList[i] | bytes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//ToDo!!!!
|
||||
}
|
||||
}
|
||||
|
||||
interface ISound{
|
||||
byte[] MakeSound();
|
||||
}
|
||||
|
||||
//Code START
|
||||
|
||||
//Code ENDE
|
||||
}
|
||||
10
Exercises/E42_Interfaces/Exercise_3.cs
Normal file
10
Exercises/E42_Interfaces/Exercise_3.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Exercises_C_Sharp.E42_Interfaces
|
||||
{
|
||||
class Exercise_3
|
||||
{
|
||||
public static void Start()
|
||||
{
|
||||
//ToDo!!!!
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user