Maha

Maha

  • NA
  • 0
  • 325.9k

Making two codes

Sep 22 2012 7:50 PM
Code highlighted is doing two jobs first it gets type then converts that type into lower case letter. How can it be split into two codes, that mean 1st code gets type and 2nd code converts that type into lower case letter.

using System;

interface person
{
String Name { get; set; }
}

class Poster : person
{
public String Name { get; set; }
}

class President : person
{
public String Name { get; set; }
public int Age { get; set; }
}

class Test
{
static void Main()
{
Poster po = new Poster();
po.Name = "Michell";
PrintDetails(po);

President pr = new President();
pr.Name = "Barack";
pr.Age = 50;
PrintDetails(pr);

Console.ReadKey();
}

static void PrintDetails(person p)
{
string type = p.GetType().Name.ToLower();
char initial = p.Name[0];
Console.WriteLine("{0} is a {1} and his initial is {2}", p.Name, type, initial);
}
}
/*
Michell is a poster and his initial is M
Barack is a president and his initial is B
*/


Answers (14)