本文整理汇总了C#中Person.IsMarried方法的典型用法代码示例。如果您正苦于以下问题:C# Person.IsMarried方法的具体用法?C# Person.IsMarried怎么用?C# Person.IsMarried使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.IsMarried方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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()));
}
示例2: 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(" ");
//.........这里部分代码省略.........
示例3: 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())
//.........这里部分代码省略.........