有一个Person类,代码如下:
public class Person
{ private string name;
private int age;
public string Name
{
get
{ return name; }
set
{ name = value; }
}
public int Age
{
get
{return age; }
set
{age=value;}
}
编写程序完成以下功能:
1)创建Person类的集合类people,该集合可以通过int型的索引符来访问.
2)在Person中重载>,<,比较Person实例的Age属性
3)给people添加GetOldest()方法,使用上面定义的重载运算符,返回一个Age最大的对象数组
4)在people类上执行ICloneable接口,提供深度复制功能
using
System;
using
System.Collections;
//
Collections类用于使用对象数组
using
System.Collections.Generic;
using
System.Text;
namespace
pro11
...
{
public class Person:ICloneable //使用ICloneable接口
...{ private string name;
private int age;
public string Name
...{
get
...{ return name; }
set
...{ name = value; }
}
public int Age

本文探讨了如何在C#中创建Person类的集合,重载比较运算符以根据Age属性比较实例,并实现GetOldest()方法以获取Age最大的对象数组。此外,还详细介绍了如何在集合类上实现ICloneable接口,从而提供深度复制功能。
最低0.47元/天 解锁文章
999

被折叠的 条评论
为什么被折叠?



