C#中关于object做函数参数的问题,,初级问题哈

2025-05-06 00:45:04
推荐回答(5个)
回答1:

1种方法:result_2 = (fuhaozu_n[j] as 你的实际类型).gailv;
2种方法:
using System.Collections;
using System.Collections.Generic;

static int kaibian(IList fuhaozu_n)

result_2 = fuhaozu_n[j].gailv;

建议使用第二种方法,泛型集合,强类型,不需要类型转换

回答2:

result_2 -= fuhaozu_n[j].gailv;
改成下面的语句:
//相当于 int yourInt = (int)ojbect;把object拆箱成自定义类,并实例化自定义类
自定义类 selfClassInstanse = (自定义类) fuhaozu_n[j];
result_2 -= selfClassInstanse.gailv;

回答3:

造型
result_2 = (fuhaozu_n[j] as 你的实际类型).gailv

回答4:

....... 你把代码贴出来啊

回答5:

把object要转换为相对应的类型