Thursday, 29 June 2017

Student Class

public class Student
   {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public Student(string firstName, string lastName)
      {
         FirstName = firstName;
         LastName = lastName;
      }
   }

static void Main(string[] args)
   {
      object[] records = { null, new Student("Joydip",
         "Kanjilal") };
      foreach (var item in records)
      {
         CheckConstantPattern(item);
      }
      Console.ReadKey();
   }

public static void CheckConstantPattern(object obj)
   {
      if (obj is null)
      Console.WriteLine("This is a constant pattern");
   }

public abstract class Employee
   {
      // Write your code here
   }
   public class SalariedEmployee : Employee
   {
      // Write your code here
   }
   public class WagedEmployee : Employee
   {
      // Write your code here
  }

Student student = new Student("Joydip", "Kanjilal");
   switch (student)
   {
      case null:
         Console.WriteLine("This is a constant pattern");
         break;
      case Student s when s.FirstName.StartsWith("J"):
         Console.WriteLine(s.FirstName);
         break;
      case var x:
         Console.WriteLine("This is a var pattern with the
            type {x?.GetType().Name} ");
         break;
      default:
         break;
   }

No comments:

Post a Comment