public static void C_ObjectGotInstanceLevelMethodsFromClass() { var giftBox = new FilledColoredGiftBox("Novel", "White"); // This method inly use value of passed argument - name. giftBox.PlaySong("Helen"); // This method use data of the gift itself giftBox.PrintCongratulation(); }
public static void D_ClassHasClassLevelMethods() { // Assume, our gifts could be delivered by single service Trace.TraceInformation($"Gifts delivery service: {FilledColoredGiftBox.GetDeliveryServiceName()}"); FilledColoredGiftBox.ChangeDeliveryServiceName("Amazon"); Trace.TraceInformation($"New gifts delivery service: {FilledColoredGiftBox.GetDeliveryServiceName()}"); // if you uncomment following code, you get an error: 'CS0176 Member cannot be accessed with an instance reference; qualify it with a type name instead' // var gift = new FilledColoredGiftBox("Detective story", "Blue"); // gift.GetDeliveryServiceName(); }
public static void B_CreateObject() { // Class with default constructor. var emptyGiftBox = new EmptyGiftBox(); emptyGiftBox .Should() .NotBeNull(); // Class with parametrized constructor var poem = "poem"; var filledGiftBox = new FilledGiftBox(poem); filledGiftBox .Should() .NotBeNull(); filledGiftBox .Gift .Should() .Be(poem); // Class with chained constructors var tale = "Tale"; var boxColor = "Yellow"; var filledColoredGiftBox = new FilledColoredGiftBox(tale, boxColor); filledColoredGiftBox .Should() .NotBeNull(); filledColoredGiftBox .Gift .Should() .Be(tale); filledColoredGiftBox .Color .Should() .Be(boxColor); }