using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace School
{
/// <summary>
/// 学生信息类
/// </summary>
public class Student
{
/// <summary>
/// 学生班级ID
/// </summary>
public int ClassID { get; set; }
/// <summary>
/// 班级名
/// </summary>
public string ClassName { get; set; }
/// <summary>
/// 学生名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 性别
/// </summary>
public string Sex { get; set; }
}
}
成员 | 说明 |
常量 | 与类关联的常数值 |
字段 | 类的变量 |
方法 | 类可执行的计算和操作 |
属性 | 与读写类的命名属性相关联的操作 |
索引器 | 与以数组方式索引类的实例相关联的操作 |
事件 | 可由类生成的通知 |
运算符 | 类所支持的转换和表达式运算符 |
构造函数 | 初始化类的实例或类本身所需的操作 |
析构函数 | 在永久丢弃类的实例之前执行的操作 |
类型 | 类所声明的嵌套类型 |
可访问性 | 含义 |
public | 访问不受限制 |
protected | 访问仅限于此类和从此类派生的类 |
internal | 访问仅限于此程序 |
protected internal | 访问仅限于此程序和从此类派生的类 |
private | 访问仅限于此类 |
using System;
namespace BoxApplication
{
class Box
{
private double length; // 长度
private double breadth; // 宽度
private double height; // 高度
public void setLength( double len )
{
length = len;
}
public void setBreadth( double bre )
{
breadth = bre;
}
public void setHeight( double hei )
{
height = hei;
}
public double getVolume()
{
return length * breadth * height;
}
}
class Boxtester
{
static void Main(string[] args)
{
Box Box1 = new Box(); // 声明 Box1,类型为 Box
Box Box2 = new Box(); // 声明 Box2,类型为 Box
double volume; // 体积
// Box1 详述
Box1.setLength(6.0);
Box1.setBreadth(7.0);
Box1.setHeight(5.0);
// Box2 详述
Box2.setLength(12.0);
Box2.setBreadth(13.0);
Box2.setHeight(10.0);
// Box1 的体积
volume = Box1.getVolume();
Console.WriteLine("Box1 的体积: {0}" ,volume);
// Box2 的体积
volume = Box2.getVolume();
Console.WriteLine("Box2 的体积: {0}", volume);
Console.ReadKey();
}
}
}
using System;
namespace LineApplication
{
class Line
{
private double length; // 线条的长度
public Line() // 构造函数
{
Console.WriteLine("对象已创建");
}
~Line() //析构函数
{
Console.WriteLine("对象已删除");
}
public void setLength( double len )
{
length = len;
}
public double getLength()
{
return length;
}
static void Main(string[] args)
{
Line line = new Line();
// 设置线条长度
line.setLength(6.0);
Console.WriteLine("线条的长度: {0}", line.getLength());
}
}
}
欢迎光临 苏飞论坛 (http://www.sufeinet.com/) | Powered by Discuz! X3.4 |