本文整理汇总了C#中Person.GetFullName方法的典型用法代码示例。如果您正苦于以下问题:C# Person.GetFullName方法的具体用法?C# Person.GetFullName怎么用?C# Person.GetFullName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.GetFullName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NoDecoratorClass
private static void NoDecoratorClass()
{
var p = new Person();
p.FirstName = "John";
p.LastName = "Public";
// Let's print out the person's full name
var fullName = p.GetFullName();
Console.WriteLine("Person: {0}", fullName);
}
示例2: Main
static void Main(string[] args)
{
Person person1 = new Person();
person1.GatherPersonDetails();
Person.Count++;
System.Console.WriteLine("Person 1#:" + " " + person1.GetFullName() + "Person #1:" + " " + person1.GetAge() + "Person #1:" + person1.IsMarried());
if (person1.IsMarried() == true)
{
Person personspouse1 = new Person();
personspouse1.GetSpouseNameAndAge();
Person.Count++;
System.Console.WriteLine("Person 1#:" + " " + personspouse1.FirstName + " " + personspouse1.Age);
}
Person person2 = new Person();
person2.GatherPersonDetails();
Person.Count++;
System.Console.WriteLine("Person 2#:" + " " + person2.GetFullName() + "Person #2:" + " " + person2.GetAge() + "Person #2:" + person2.IsMarried());
if (person2.IsMarried() == true)
{
Person personspouse2 = new Person();
personspouse2.GetSpouseNameAndAge();
Person.Count++;
System.Console.WriteLine("Person 2#:" + " " + personspouse2.FirstName + " " + personspouse2.Age);
}
Person person3 = new Person();
person3.GatherPersonDetails();
Person.Count++;
System.Console.WriteLine("Person 3#:" + " " + person3.GetFullName() + "Person #3:" + " " + person3.GetAge() + "Person #3:" + person3.IsMarried());
if (person3.IsMarried() == true)
{
Person personspouse3 = new Person();
personspouse3.GetSpouseNameAndAge();
Person.Count++;
System.Console.WriteLine("Person 3#:" + " " + personspouse3.FirstName + " " + personspouse3.Age);
}
double.Parse(System.Console.WriteLine("Average Age:" + GetAverageAge()));
}
示例3: PrintResults
static void PrintResults(Person NewPerson, bool CanVote)
{
//** call method GetFullName on class Person to return a formatted name **
System.Console.WriteLine();
System.Console.WriteLine("*******************************");
System.Console.WriteLine("Name entered: " + NewPerson.GetFullName());
System.Console.WriteLine("Height (CM): " + NewPerson.TotalHeightCM);
string prompt = " is ";
if (CanVote == false)
{
prompt += "not ";
}
prompt += "eligible to vote.";
System.Console.WriteLine(NewPerson.FirstName + prompt);
System.Console.ReadKey();
}
示例4: Main
static void Main(string[] args)
{
Person Person1 = new Person();//creat new person
Person1.GetFullName();//geting full name
Person1.PrintNameAndAge(); // printing fullname and age
Person1.NexStep();//geting information about spouse if it has one, go and se person.Nextstep() method
Person Person2 = new Person();
Person2.GetFullName();
Person2.PrintNameAndAge();
Person2.NexStep();
Person Person3 = new Person();
Person3.GetFullName();
Person3.PrintNameAndAge();
Person3.NexStep();
System.Console.WriteLine(" The Average Age is " +Person3.FinalAverageAge());//this will be the average age
//of all persons not so good as a code
System.Console.WriteLine("pres any key to continue..");
System.Console.ReadKey();
}
示例5: Main
static void Main(string[] args)
{
Person P1 = new Person();
P1.GetFullName();
P1.PrintNameAndAge();
P1.MaritalStatus();
Person P2 = new Person();;
P2.GetFullName();
P2.PrintNameAndAge();
P2.MaritalStatus();
Person P3 = new Person();
P3.GetFullName();
P3.PrintNameAndAge();
P3.MaritalStatus();
System.Console.WriteLine("Average age of all people is " + P3.AverageAge());
System.Console.WriteLine("Press any key to continue...");
System.Console.ReadLine();
}
示例6: Main
static void Main(string[] args)
{
//create a person object
Person personObject = new Person();
personObject.FirstName = "Han";
personObject.LastName = "Solo";
string fullName = personObject.GetFullName();
//use the fullname method of person
Console.WriteLine(fullName);
//create another person object using the initializer style
//create a person object
Person person2Object = new Person() {
FirstName = "Luke",
LastName = "Skywalker"
};
string fullName2 = person2Object.GetFullName();
//use the fullname method of second person
Console.WriteLine(fullName2);
//create an employee which is a subclass of person
Employee employee = new Employee();
employee.FirstName = "Darth";
employee.LastName = "Vader";
string fullEmployeeName = employee.GetFullName();
employee.Salary = 1000000;
//write the employee name
Console.WriteLine(fullEmployeeName);
//Console.WriteLine("The employee named {0} {1} has a salary of {2:c} a year",
//employee.FirstName,
//employee.LastName,
//employee.Salary);
Console.WriteLine($"The employee named {employee.FirstName} {employee.LastName} has a salary of {employee.Salary:c0} a year");
Console.ReadLine();
//implementing interfaces
//log messages to the console
ConsoleLogger cLogger = new ConsoleLogger();
cLogger.LogError("Some error occurred.");
cLogger.LogInfo("All's well!");
//log messages to the event log
WindowsEventLogLogger wLogger = new WindowsEventLogLogger();
wLogger.LogError("Some error occurred.");
wLogger.LogInfo("All's well!");
//log messages to the database
DatabaseLogger dLogger = new DatabaseLogger();
dLogger.LogError("Some error occurred.");
dLogger.LogInfo("All's well!");
List<ILogger> loggers = new List<ILogger>();
loggers.Add(new ConsoleLogger());
loggers.Add(new WindowsLogLogger());
loggers.Add(new DatabaseLogger());
foreach (ILogger logger in loggers)
{
logger.LogError("Some error occurred.");
logger.LogInfo("All's well!");
}
Console.ReadKey();
}
示例7: Main
static void Main(string[] args)
{
// bool isMarried = false;
string married = null;
Person p1 = new Person();
// Get name data
p1.FirstName = "Lauren";
p1.LastName = "Mazzoli";
p1.Age = 50;
p1.Spouse = null;
Person.NbrPeople++;
p1.PrintNameAndAge();
Person.SumOfAllAges += p1.Age;
// get marital data
while ((married != "Y") && (married != "N"))
{
System.Console.Write("Hi " + p1.FirstName + ", Are you married (Y/N)?");
married = System.Console.ReadLine();
}
// isMarried = bool.Parse(System.Console.ReadLine());
if (married == "Y")
// if (isMarried)
{
Person s1 = new Person();
p1.Spouse = s1;
s1.FirstName = "Lou";
s1.LastName = p1.LastName;
s1.Age = 48;
Person.NbrPeople++;
System.Console.WriteLine("Your spouse is: " + s1.GetFullName() + ".");
s1.PrintNameAndAge();
Person.SumOfAllAges += s1.Age;
s1.Spouse = p1;
// s1.GetSpouseData();
}
else
{
System.Console.WriteLine("You have no Spouse.");
}
Person p2 = new Person();
p2.FirstName = "Carolyn";
p2.LastName = "Mecenas";
p2.Age = 53;
p2.PrintNameAndAge();
Person.SumOfAllAges += p2.Age;
p2.Spouse = null;
married = null;
Person.NbrPeople++;
while ((married != "Y") && (married != "N"))
{
System.Console.Write("Hi " + p2.FirstName + ", Are you married (Y/N)?");
married = System.Console.ReadLine();
}
//isMarried= bool.Parse(System.Console.ReadLine());
if (married == "Y")
{
Person s2 = new Person();
s2.FirstName = "Mark";
s2.LastName = p2.LastName;
s2.Age = 55;
s2.Spouse = p2;
p2.Spouse = s2;
Person.NbrPeople++;
System.Console.WriteLine("Your spouse is: " + s2.GetFullName() + ". ");
s2.PrintNameAndAge();
Person.SumOfAllAges += s2.Age;
// s2.GetSpouseData
//
}
else
{
System.Console.WriteLine("You have no Spouse.");
}
System.Console.WriteLine("Total Sum of all Ages: " + Person.SumOfAllAges);
System.Console.WriteLine("Total Nbr of People: " + Person.NbrPeople);
System.Console.WriteLine("The Average Age is: " + (Person.SumOfAllAges /Person.NbrPeople));
System.Console.WriteLine("Press any key to continue...");
System.Console.ReadLine();
}