C#数组如何添加整个类下的成员

2025-04-01 14:08:54

1、类的成员如图所示:

C#数组如何添加整个类下的成员

2、使用的是对象数组保存类的成员。如图所示:

C#数组如何添加整个类下的成员

3、所有的代码如下:using System;namespace ArrayApplication{ class MyArray { static void Main(string[] args) { Box[] n = new Box[10]; /* n 是一个带有 10 个对象的数组 *//*第一组数据*/n[1].length=18.0;n[1].breadth=20.3;n[1].height=30.5; } }class Box { public double length; // 长度 public double breadth; // 宽度 public double height; // 高度 }}

C#数组如何添加整个类下的成员

4、如果需要保存多组数据赋值方式如下:us坡纠课柩ing System;namespace ArrayApplication{ 艘早祓胂class MyArray { static void Main(string[] args) { Box[] n = new Box[10]; /* n 是一个带有 10 个对象的数组 *//*第一组数据*/n[1].length=18.0;n[1].breadth=20.3;n[1].height=30.5;/*第二组数据*/n[2].length=12.5;n[2].breadth=25.3;n[2].height=35.5; } }class Box { public double length; // 长度 public double breadth; // 宽度 public double height; // 高度 }}

C#数组如何添加整个类下的成员
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:60
  • 阅读量:27
  • 阅读量:68
  • 阅读量:86
  • 阅读量:45
  • 猜你喜欢