Skip to content

Commit

Permalink
Tested IsExpression to get parent class from a child class
Browse files Browse the repository at this point in the history
  • Loading branch information
mossykazemi committed Oct 24, 2020
1 parent d3e284c commit 33f455c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions IsExpressionsExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@ class Program
{
static void Main(string[] args)
{

PersonCar pc = new PersonCar("Mostafa", "Kazemi", 30, "Tesla", 3);

if (pc is Person p)
{
Console.WriteLine($"Name : {p.Name} , Family : {p.Family} , Age : {p.Age}");
}

Console.ReadKey();
}
}

class Person
{
public string Name { get; set; }
public string Family { get; set; }
public int Age { get; set; }
}

class PersonCar : Person
{
public string CarName { get; set; }
public int CarModel { get; set; }


public PersonCar(string name, string family, int age, string carName, int carModel)
{
Name = name;
Family = family;
Age = age;
CarName = carName;
CarModel = carModel;
}
}
}

0 comments on commit 33f455c

Please sign in to comment.