📜  C# if with obj params - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:10.846000             🧑  作者: Mango

代码示例1
object obj = new Person
{
    FirstName = "Kathleen",
    LastName = "Dollard",
    Address = new Address { City = "Seattle" }
};

if (obj is Person { Address: { City: "Seattle" } })
    Console.WriteLine("Seattle");

if (obj is Person { Address.City: "Seattle" }) // Extended property pattern
    Console.WriteLine("Seattle");