当前位置: 首页>>代码示例>>C#>>正文


C# Person.PrintNameAndAge方法代码示例

本文整理汇总了C#中Person.PrintNameAndAge方法的典型用法代码示例。如果您正苦于以下问题:C# Person.PrintNameAndAge方法的具体用法?C# Person.PrintNameAndAge怎么用?C# Person.PrintNameAndAge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Person的用法示例。


在下文中一共展示了Person.PrintNameAndAge方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrintData

 public static void PrintData(Person p)
 {
     p.PrintNameAndAge("");
     if (p.Spouse != null)
     {
         p.Spouse.PrintNameAndAge("Spouse ");
     }
     System.Console.WriteLine();
 }
开发者ID:LaurenMazzoli,项目名称:IT-1050,代码行数:9,代码来源:Program.cs

示例2: 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();
        }
开发者ID:MaximSBolocan,项目名称:1050-homework,代码行数:21,代码来源:Program.cs

示例3: 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();
        }
开发者ID:SamDelBrocco,项目名称:IT-1050,代码行数:21,代码来源:Program.cs

示例4: Main

        static void Main(string[] args)
        {
            Person P1 = new Person();
            P1.GetInfo();
            P1.CreateSpouseIfMarried();

            Person P2 = new Person();
            P2.GetInfo();
            P2.CreateSpouseIfMarried();

            Person P3 = new Person();
            P3.GetInfo();
            P3.CreateSpouseIfMarried();

            P1.PrintNameAndAge();

            P2.PrintNameAndAge();

            P3.PrintNameAndAge();

            System.Console.WriteLine("The average age is " + Person.AverageAge());
            System.Console.ReadKey();
        }
开发者ID:kcbwilson,项目名称:IT-1050,代码行数:23,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            Person.AverageAge = 0;
            Person.SumOfAllAges = 0;
            Person.Count = 0;

            Person person1 = new Person();
            System.Console.WriteLine("What is your first name?");
            person1.FirstName = System.Console.ReadLine();
            System.Console.WriteLine("What is your last name?");
            person1.LastName = System.Console.ReadLine();
            System.Console.WriteLine("How old are you?");
            person1.Age = int.Parse(System.Console.ReadLine());
            Person.Count++;
            Person.SumOfAllAges += person1.Age;

            System.Console.WriteLine("       ");
            System.Console.WriteLine("       ");

            System.Console.WriteLine("Are you married?  (y/n)");
            if (System.Console.ReadLine().ToLower().StartsWith("y"))
             {
                System.Console.WriteLine("What is your spouse's name?");
                person1.Spouse = new Person();
                person1.Spouse.FirstName = System.Console.ReadLine();
                System.Console.WriteLine("How old is your spouse?");
                person1.Spouse.Age = int.Parse(System.Console.ReadLine());
                Person.Count++;
                Person.SumOfAllAges += person1.Spouse.Age;
            }

            System.Console.WriteLine("       ");
            System.Console.WriteLine("       ");

            Person person2 = new Person();
            System.Console.WriteLine("What is your first name?");
            person2.FirstName = System.Console.ReadLine();
            System.Console.WriteLine("What is your last name?");
            person2.LastName = System.Console.ReadLine();
            System.Console.WriteLine("How old are you?");
            person2.Age = int.Parse(System.Console.ReadLine());
            Person.Count++;
            Person.SumOfAllAges += person2.Age;

            System.Console.WriteLine("       ");
            System.Console.WriteLine("       ");

            System.Console.WriteLine("Are you married? (y/n)");
            if (System.Console.ReadLine().ToLower().StartsWith("y"))
            {
                System.Console.WriteLine("What is your spouse's name?");
                person2.Spouse = new Person();
                person2.Spouse.FirstName = System.Console.ReadLine();
                System.Console.WriteLine("How old is your spouse?");
                person2.Spouse.Age = int.Parse(System.Console.ReadLine());
                Person.Count++;
                Person.SumOfAllAges += person2.Spouse.Age;
            }

            System.Console.WriteLine("       ");
            System.Console.WriteLine("       ");

            Person person3 = new Person();
            System.Console.WriteLine("What is your first name?");
            person3.FirstName = System.Console.ReadLine();
            System.Console.WriteLine("What is your last name?");
            person3.LastName = System.Console.ReadLine();
            System.Console.WriteLine("How old are you?");
            person3.Age = int.Parse(System.Console.ReadLine());
            Person.Count++;
            Person.SumOfAllAges += person3.Age;

            System.Console.WriteLine("       ");
            System.Console.WriteLine("       ");

            System.Console.WriteLine("Are you married? (y/n)");
            if (System.Console.ReadLine().ToLower().StartsWith("y"))
            {
                System.Console.WriteLine("What is your spouse's name?");
                person3.Spouse = new Person();
                person3.Spouse.FirstName = System.Console.ReadLine();
                System.Console.WriteLine("How old is your spouse?");
                person3.Spouse.Age = int.Parse(System.Console.ReadLine());
                Person.Count++;
                Person.SumOfAllAges += person3.Spouse.Age;

            }

            System.Console.WriteLine("       ");
            System.Console.WriteLine("       ");

            System.Console.WriteLine();
            person1.PrintNameAndAge();
            if (person1.IsMarried())
            {
                person1.Spouse.PrintNameAndAge();

            }

            System.Console.WriteLine("       ");
//.........这里部分代码省略.........
开发者ID:bbosowski6690,项目名称:IT-1050,代码行数:101,代码来源:Program.cs

示例6: 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();
        }
开发者ID:camilleonly,项目名称:IT-1050,代码行数:86,代码来源:Program.cs

示例7: Main

        static void Main(string[] args)
        {
            Person.Count = 0;

            Person p1 = new Person();
            Person.Count++;
            Person spouse1 = new Person();
            p1.Spouse = spouse1;

            p1.firstName = Question.Ask("What is your first name?");
            p1.lastName = Question.Ask("What is your last name?");
            p1.Age = Question.AskNumber("What is your age?");
            p1.married = Question.AskYesOrNo("Are you married?");
            p1.spouseOrNone();

            //If not married, give "none" as spouse name and 0 as spouse age.

            spouse1.firstName = Question.Ask("What is your spouse's name?");
            spouse1.Age = Question.AskNumber("What is your spouse's age?");

            Console.WriteLine(" ");
            Console.WriteLine("Next person:");

            Person p2 = new Person();
            Person.Count++;
            Person spouse2 = new Person();
            p2.Spouse = spouse2;

            p2.firstName = Question.Ask("What is your first name?");
            p2.lastName = Question.Ask("What is your last name?");
            p2.Age = Question.AskNumber("What is your age?");
            p2.married = Question.AskYesOrNo("Are you married?");
            p2.spouseOrNone();

            spouse2.firstName = Question.Ask("What is your spouse's name?");
            spouse2.Age = Question.AskNumber("What is your spouse's age?");

            Console.WriteLine(" ");
            Console.WriteLine("Next person:");

            Person p3 = new Person();
            Person.Count++;
            Person spouse3 = new Person();
            p3.Spouse = spouse3;

            p3.firstName = Question.Ask("What is your first name?");
            p3.lastName = Question.Ask("What is your last name?");
            p3.Age = Question.AskNumber("What is your age?");
            p3.married = Question.AskYesOrNo("Are you married?");
            p3.spouseOrNone();

            spouse3.firstName = Question.Ask("What is your spouse's name?");
            spouse3.Age = Question.AskNumber("What is your spouse's age?");

            Console.WriteLine(" ");

            Console.WriteLine("Person 1:");
            p1.PrintNameAndAge();

            Console.WriteLine(" ");

            Console.WriteLine("Person 2:");
            p2.PrintNameAndAge();

            Console.WriteLine(" ");

            Console.WriteLine("Person 3:");
            p3.PrintNameAndAge();

            Person.averageAge = (p1.Age + p2.Age + p3.Age + spouse1.Age + spouse2.Age + spouse3.Age) / Person.Count;

            Console.WriteLine("Average age: " + Person.averageAge);
            Console.ReadLine();
        }
开发者ID:pieisgood4u,项目名称:IT-1050-master,代码行数:74,代码来源:Program.cs

示例8: Main

        static void Main(string[] args)
        {
            /*
            PROGRAM PURPOSE:
                - Takes in name, age, and marital status of a person (Person object).
                - Asks if the person has a spouse, and if so, creates another connected person object.
                - Keeps track of the number of person objects and the sum of all of their ages.
                - Finds the average age of all person objects.
                - Prints out all info to console.
            */
            
            //Declare/Instantiate Person objects

            Person p1 = new Person();
            Person p2 = new Person();

            //Invoke methods for each Person object

            // Person 1 info

            System.Console.WriteLine("Enter information for person 1: ");
            System.Console.WriteLine();

            p1.AskForPersonInfo();

            // Person 2 info

            System.Console.WriteLine();
            System.Console.WriteLine("Enter information for person 2: ");
            System.Console.WriteLine();
              
            p2.AskForPersonInfo();

            // Print results for all person objects

            System.Console.WriteLine();
            System.Console.WriteLine("Results: ");
            System.Console.WriteLine();

            p1.PrintNameAndAge();               // Print age of person 1

            if (p1.isMarried)                   // If person 1 is married, print their spouse's age
            {
                p1.spouse.PrintNameAndAge();
            }

            p2.PrintNameAndAge();               // Print age of person 2

            if (p2.isMarried)                   // If person 2 is married, print their spouse's age
            {
                p2.spouse.PrintNameAndAge();
            }

            System.Console.WriteLine();
            Person.PrintAverageAge();           // Print average age of all person objects

            //End program

            System.Console.WriteLine();
            System.Console.Write("Press <enter> to continue...");
            while (System.Console.ReadKey(true).Key != System.ConsoleKey.Enter) { }

        }
开发者ID:JennJackson,项目名称:IT-1050,代码行数:63,代码来源:Program.cs

示例9: Main

        static void Main(string[] args)
        {
            //After you have collected this information, compute and print all values:
            //Full name and age of every person, including spouses.
            //Average age of all people.

            Person.AverageAge = 0;
            Person.SumOfAges = 0;
            Person.Count = 0;

            Person Person1 = new Person();
            System.Console.WriteLine("What is your first name?");
            Person1.FirstName = System.Console.ReadLine();
            System.Console.WriteLine("What is your last name?");
            Person1.LastName = System.Console.ReadLine();
            System.Console.WriteLine("How old are you?");
            Person1.Age = int.Parse(System.Console.ReadLine());
            Person.Count++;
            Person.SumOfAges += Person1.Age;

            System.Console.WriteLine("Are you married?");
            if (System.Console.ReadLine().ToLower().StartsWith("y"))
            {

                Person1.Spouse = new Person();

                System.Console.WriteLine("What is your spouse's name?");

                Person1.Spouse.FirstName = System.Console.ReadLine();
                System.Console.WriteLine("How old is your spouse?");
                Person1.Spouse.Age = int.Parse(System.Console.ReadLine());
                Person.SumOfAges += Person1.Spouse.Age;

                Person1.Spouse.Spouse = Person1;

            }

            Person Person2 = new Person();
            System.Console.WriteLine("What is the first name of another person?");
            Person2.FirstName = System.Console.ReadLine();
            System.Console.WriteLine("What is their last name?");
            Person2.LastName = System.Console.ReadLine();
            System.Console.WriteLine("How old are they?");
            Person2.Age = int.Parse(System.Console.ReadLine());
            Person.Count++;
            Person.SumOfAges += Person2.Age;

            System.Console.WriteLine("Are they married?");
            if (System.Console.ReadLine().ToLower().StartsWith("y"))
            {

                Person2.Spouse = new Person();

                System.Console.WriteLine("What is their spouse's name?");
                Person2.Spouse.FirstName = System.Console.ReadLine();
                System.Console.WriteLine("How old is their spouse?");
                Person2.Spouse.Age = int.Parse(System.Console.ReadLine());
                Person.SumOfAges += Person2.Spouse.Age;

                Person2.Spouse.Spouse = Person2;

            }

            Person Person3 = new Person();
            System.Console.WriteLine("What is the first name of another person?");
            Person3.FirstName = System.Console.ReadLine();
            System.Console.WriteLine("What is their last name?");
            Person3.LastName = System.Console.ReadLine();
            System.Console.WriteLine("How old are they?");
            Person3.Age = int.Parse(System.Console.ReadLine());
            Person.Count++;
            Person.SumOfAges += Person3.Age;

            System.Console.WriteLine("Are they married?");
            if (System.Console.ReadLine().ToLower().StartsWith("y"))
            {

                Person3.Spouse = new Person();

                System.Console.WriteLine("What is their spouse's name?");
                Person3.Spouse.FirstName = System.Console.ReadLine();
                System.Console.WriteLine("How old is their spouse?");
                Person3.Spouse.Age = int.Parse(System.Console.ReadLine());

                Person.SumOfAges += Person3.Spouse.Age;

                Person3.Spouse.Spouse = Person3;
            }

            System.Console.WriteLine();
            Person1.PrintNameAndAge();
            if (Person1.IsMarried())
            {
                Person1.Spouse.PrintNameAndAge();

            }

            System.Console.WriteLine();
            Person2.PrintNameAndAge();
            if (Person2.IsMarried())
//.........这里部分代码省略.........
开发者ID:mkrause9,项目名称:IT1025,代码行数:101,代码来源:MalloryKrauseLab2.cs


注:本文中的Person.PrintNameAndAge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。