<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace useClass2
{
public enum Genders { Female = 0 ,Male = 1 }
public class Person {
// / <summary>
// / _name is private field,Name is public attribute,姓名前后的空去除掉
// / </summary>
private string _name;
public string Name {
get { return this ._name; }
set { this ._name = value.Trim(); }
}
// / <summary>
// / _age:1-120之间,超出这个范围,默认设置为20
// / </summary>
private int _age;
public int Age {
get { return this ._age; }
set {
if ((value > 120 ) || (value < 1 )) this ._age = 20 ;
else this ._age = value;
}
}
// / <summary>
// / _gender
// / </summary>
private Genders _gender;
public Genders Gender {
get { return this ._gender; }
set { this ._gender = value; }
}
}
class Program
{
static void Main(string[] args)
{
Person aPerson = new Person();
aPerson.Name = " Rorely " ;
aPerson.Age = 19 ;
aPerson.Gender = Genders.Female;
PrintPerson(aPerson);
System.Console.ReadLine();
}
static void PrintPerson(Person a) {
System.Console.WriteLine( " {0},{1},{2} " ,a.Name,a.Age,a.Gender);
}
}
}
结果:
rorely,19,Female
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace useClass2
{
public enum Genders { Female = 0 ,Male = 1 }
public class Person {
// / <summary>
// / _name is private field,Name is public attribute,姓名前后的空去除掉
// / </summary>
private string _name;
public string Name {
get { return this ._name; }
set { this ._name = value.Trim(); }
}
// / <summary>
// / _age:1-120之间,超出这个范围,默认设置为20
// / </summary>
private int _age;
public int Age {
get { return this ._age; }
set {
if ((value > 120 ) || (value < 1 )) this ._age = 20 ;
else this ._age = value;
}
}
// / <summary>
// / _gender
// / </summary>
private Genders _gender;
public Genders Gender {
get { return this ._gender; }
set { this ._gender = value; }
}
}
class Program
{
static void Main(string[] args)
{
Person aPerson = new Person();
aPerson.Name = " Rorely " ;
aPerson.Age = 19 ;
aPerson.Gender = Genders.Female;
PrintPerson(aPerson);
System.Console.ReadLine();
}
static void PrintPerson(Person a) {
System.Console.WriteLine( " {0},{1},{2} " ,a.Name,a.Age,a.Gender);
}
}
}
结果:
rorely,19,Female