12386人加入学习
(21人评价)
C#编程-第二季-面向对象-宇宙最简单2021最新版

制作完成于2021-10月20日 使用VS2019

价格 免费

系统自带的list,如果超出范围后,会进行预处理的报错

 

throw 抛出异常,new,System.ArgumentOutOfRangeExcption("报错信息");

如果命名空间已有了System,则不需要加System

 

IndexOutOfRangeException

ArgumentOutOfRangeException

 

  • 修复 IndexOutOfRangeException:检查循环边界和集合访问逻辑。

  • 使用 ArgumentOutOfRangeException:在公共方法中验证参数,明确约束(如 if (param < 0) throw ...)。

  • 集合访问差异List<T> 的索引器会抛出 ArgumentOutOfRangeException(手动验证),而数组会抛出 IndexOutOfRangeException(自动抛出)。

[展开全文]

访问元素

public T this[int index]

{

get{

return data[int index]

{

set

{

data[index]=value;

}

list[10]

List

 

[展开全文]

public T this[int index]{
get{
if(index<0 || index > count -1){
throw new Argumentout0fRangeException("参数超出范围了");
}
return data[index];
}
 

[展开全文]

授课教师

问问题加入A计划,有专门负责答疑的老师哦!!!

课程特色

下载资料(1)
视频(60)