Exemplo n.º 1
0
        static async Task Main(string[] args)
        {
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Null Coalescing Assignment Example");
            Console.WriteLine("----------------------");
            string?defaultVal = null;

            defaultVal ??= "PlaceHolder";
            Console.WriteLine(defaultVal);

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Async Streams Example");
            Console.WriteLine("----------------------");
            var orderFactory = new OrderFactory();

            Console.WriteLine($"[{ThreadId}]Enumerating orders...");
            await foreach (var order in orderFactory.MakeOrders(5))
            {
                Console.WriteLine($"[{ThreadId}]Received order {order.Id}.");
            }
            Console.WriteLine($"[{ThreadId}]All orders created!");

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Default interface Example");
            Console.WriteLine("----------------------");
            var dog     = new DogWidget();
            var cat     = new CatWidget();
            var hamster = new HamsterWidget();

            IAnimalWidget.SetAmountToFeed(20);
            var animals = new IAnimalWidget[] { dog, cat, hamster };

            dog.Feed();
            foreach (var animal in animals)
            {
                animal.Feed();
                Console.WriteLine($"Happiness level for {animal.Name}: {animal.Happiness}");
            }

            Console.WriteLine(Environment.NewLine);
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Utf8JsonReader Example");
            Console.WriteLine("----------------------");
            var jsonFile = File.ReadAllBytes("sample.json");
Exemplo n.º 2
0
        public static void Demo()
        {
            IAnimalWidget.SetAmountToFeed(45);

            var dog     = new DogWidget();
            var cat     = new CatWidget();
            var hamster = new HamsterWidget();

            var animals = new IAnimalWidget[] { dog, cat, hamster };

            //dog.Feed();
            hamster.Feed();

            foreach (var animal in animals)
            {
                animal.Feed();
                Console.WriteLine($"Happiness level for {animal.Name}: {animal.Happiness}");
            }
        }
Exemplo n.º 3
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            IAnimalWidget.SetAmountToFeed(20);
            var dog     = new DogWidget();
            var cat     = new CatWidget();
            var hamster = new HamsterWidget();

            var animals = new IAnimalWidget[] { dog, cat, hamster };

            dog.Feed();

            foreach (var animal in animals)
            {
                animal.Feed();
                Console.WriteLine($"Happiness level for {animal.Name}: {animal.Happiness}");
            }

            var orderFactory = new OrderFactory();

            Console.WriteLine($"[{ThreadId}]Enumerating orders...");

            await foreach (var order in orderFactory.MakeOrdersAsync(5))
            {
                Console.WriteLine($"[{ThreadId}]Received order {order.Id}.");
            }

            Console.WriteLine($"[{ThreadId}]All orders created!");

            var demo = new StaticLocalDemo();

            demo.Run();

            using var resource = new DisposableResource();

            Console.WriteLine($"Using resource: {resource.Value}");


            Console.WriteLine("All finished!");
            Console.WriteLine("Hello World!");
        }