using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace useClass
{
/// <summary>
/// define Genders ,type is enum
/// </summary>
public enum Genders {
Female=0,
Male=1
}
public class Person {
private string name;
private int age;
private Genders gender;
/// <summary>
/// default class constructor without any parameters
/// </summary>
public Person() { }
/// <summary>
/// class constructor with all fields
/// </summary>
/// <param name="name"></param>
/// <param name="age"></param>
/// <param name="gender"></param>
public Person(string name, int age, Genders gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
/// <summary>
/// getters
/// </summary>
/// <returns></returns>
public string getName() {
return this.name;
}
public int getAge() {
return this.age;
}
public Genders getGender() {
return this.gender;
}
/// <summary>
/// setters
/// </summary>
/// <param name="name"></param>
public void setName(string name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public void setGender(Genders gender) {
this.gender = gender;
}
}
class Program
{
static void Main(string[] args)
{
Person aPerson = new Person();
aPerson.setName("rorely");
aPerson.setAge(19);
aPerson.setGender(0);
System.Console.WriteLine("{0},{1},{2}",aPerson.getName(),aPerson.getAge(),aPerson.getGender());
Person bPerson = new Person("Rose",23,Genders.Female);
System.Console.WriteLine("{0},{1},{2}", bPerson.getName(), bPerson.getAge(), bPerson.getGender());
System.Console.ReadLine();
}
}
}
结果:
rorely,19,Female
Rose,23,Female
posted on 2009-10-25 18:52
期待明天 阅读(516)
评论(0) 编辑 收藏 所属分类:
CSharp