Pattern Matching



Pattern Matching using is an expression in c#
It is a feature that performs matching on data or any object. We can perform pattern matching using:

1. is an expression
2. switch statement.
is expression checks whether an object is compatible with a given type or not.

Example: 

using System;  
namespace PatternMatching
{  
    class Address
    {  
        public string City { get; set; } = "Mumbai";  
    }  
    class PatternMatchingClass
    {  
        public static void Main(string[] args)  
        {  
            Address address= new Address();  
            if(address is Address)  
            {  
                Console.WriteLine(address.City);  
            }  
        }  
    }  
}  

0 Comment's

Comment Form