title: How can I use the same function for different type parameters which have the same member?
body: <p>BHere is the sample code, I've defined two classes. How can I use the <code>Output</code> function to output the member which has the same name in two different classes?</p>
  
  <pre><code>class A
  {
      public string Name { get; set; }
      public int Age { get; set; }
      public string Email { get; set; }
  
      public A(string name, int age, string email)
      {
          Name = name;
          Age = age;
          Email = email;
      }
  }
  
  class B
  {
      public string Name { get; set; }
      public int Age { get; set; }
      public string Location { get; set; }
  
      public B(string name, int age, string location)
      {
          Name = name;
          Age = age;
          Location = location;
      }
  }
  
  void Output(object obj)
  {
      // How can I convert the object 'obj' to class A or class B
      // in order to output its 'Name' and 'Age'
      Console.WriteLine((A)obj.Name); // If I pass a class B in pararmeter, output error.
  }
  </code></pre>