TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
326k
GetType()
Sep 3 2012 5:34 PM
This program is given in the following C# Corner website http://www.c-sharpcorner.com/Forums/Thread/153399/.
Problem with this code
string type =
p.GetType().
Name
.ToLower();
In order to get the type
p.GetType()
is understood but to have it all lowercase letters it must be
(p.GetType()).ToLower();
Please explain how did "Name" come in between? Problem is highlighted in the program.
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
*/
Reply
Answers (
5
)
automatic property
C# write and read text file