嵌套类
来源:互联网 发布:头颅移植 知乎 编辑:程序博客网 时间:2024/05/17 03:50
在类的内部或结构的内部定义的类型称为嵌套类型,又称内部类型
namespace 例5_6.嵌套类
{
class Program
{
static void Main(string[] args)
{
int x1 = Convert.ToInt32(Console .ReadLine());
int x2 = Convert.ToInt32(Console.ReadLine());
int y1 = Convert.ToInt32(Console.ReadLine());
int y2 = Convert.ToInt32(Console.ReadLine());
Rectangle my = new Rectangle(x1, y1, x2, y2);
Console.WriteLine(my.Area());
Console.ReadLine();
}
}
class Rectangle
{
private Point topLeft;
private Point bottomRight;
public Rectangle(int lx, int ly, int rx, int ry)
{
topLeft = new Point(lx,ly); //实例化
bottomRight = new Point(rx, ry);
}
class Point //内部类
{
private int x;
private int y;
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public int X //返回x的值
{
get { return x; }
}
public int Y //返回y的值
{
get { return y; }
}
}
public int Area()
{
return (bottomRight.X - topLeft.X) * (bottomRight.Y - topLeft.Y);
}
}
}
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- 嵌套类
- poj1006
- 路径中斜杠/与反斜杠\ 的区别
- Spark RDD API详解(一) Map和Reduce
- maven学习-01
- 菜鸟学Android笔记(十二):Tomcat的安装配置
- 嵌套类
- 如何从ST官网上下载资源STM32标准库Standard Peripheral LibrariesV3.5.0
- 深入理解计算机系统 perflab 程序性能优化实验
- Single Number II -- leetcode
- solrCloud部署
- 三等奖我就和我和好
- Android Fragment使用
- 使用FileUtils来简化文件操作
- 常见经典音频运放(一般作前级用)