計算機科学のブログ

LINQ and lambdas - Get control of your data - refactoring, lambda operator, property, method

Head First C Sharp: A Learner’s Guide to Real-World Programming with C Sharp and .NET (Andrew Stellman(著)、Jennifer Greene(著)、O’Reilly Media)の Chapter 9(LINQ and lambdas - Get control of your data)、p.511(Sharpen your pencil)の解答を求めてみる。

コード

NectarCollector.cs

namespace ConsoleApp3;

public class NectarCollector : Bee
{
    private const float NECTAR_COLLECTED_PER_SHIFT = 33.25f;
    public override float CosntPerShift { get => 1.95f; }
    protected override void DoJob()
    {
        HoneyVault.CollectedNectar(NECTAR_COLLECTED_PER_SHIFT);
    }
    public NectarCollector() : base("Nectar Collector") { }
}

コード

ScaryScary.cs

namespace ConsoleApp3;

public class ScaryScary : FunnyFunny, IScaryClown
{
    private int scaryThingCount;
    public ScaryScary(string funnyThingIHave, int scaryThingCount) : base(funnyThingIHave)
    {
        this.scaryThingCount = scaryThingCount;
    }

    public string ScaryThingIHave { get => $"{scaryThingCount} spiders"; }

    public void ScareLittleChildren() => Console.WriteLine($"Boo! Gotcha! Look at my {ScaryThingIHave}!");
}