Last active
June 6, 2021 14:21
-
-
Save rstropek/d65641de6e913b8de6592a756709b244 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
var heroes = new List<IHero> | |
{ | |
new Hero("Homelander", new(true, true)), | |
new Hero("Stormfront", new(true, false)), | |
}; | |
// Old: if (heroes[0] is Hero { Flying: { CanFlyInSpace: true } }) | |
if (heroes[0] is Hero { Flying.CanFlyInSpace: true }) | |
{ | |
Console.WriteLine("Hero can fly on earth"); | |
} | |
class Flying | |
{ | |
public bool CanFlyOnEarth { get; set; } | |
public bool CanFlyInSpace { get; set; } | |
public Flying(bool canFlyOnEarth, bool canFlyInSpace) | |
=> (CanFlyOnEarth, CanFlyInSpace) = (canFlyOnEarth, canFlyInSpace); | |
} | |
interface IHero { } | |
class Hero : IHero | |
{ | |
public string Name; | |
public Flying Flying; | |
public Hero(string name, Flying flying) | |
=> (Name, Flying) = (name, flying); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment