c#中的int?[]

来源:百度知道 编辑:UC知道 时间:2024/05/22 18:07:06
public int?[] InsertTest(int? parentId, string name, DateTime? publishTime, decimal? price, bool? isGood, out int? minId)
{
// 仅为说明如何做错误处理
if (String.IsNullOrEmpty(name))
throw new ArgumentException("参数不能是空", "name");

int? id = null;
int? count = null;
minId = null;

Singleton<TestTableAdapter>.Instance.InsertTest(parentId, name, publishTime, price, isGood, ref id, ref count, ref minId);
return new int?[] { id, count };
}
//请问这里面的?是什么意思?
//大概讲一下代码的意思?
//谢谢

这是面像对像的又一经典想法.....用INT?可以传NULL值进去...
当参数是INT型时,你只能传一个INT型进去...,但你常常想在接收的INT型要做一些意外处理.比如传-1就代表是错误数据,你就执行A,如果非-1就扫行B......但有时候-1也可能是是正确的值,你又想处理意外,你就用-10000或,-100......但这样程序就比较难以控制,如果-100到时候又是有用的数据怎么办??这时你用INT?传一个NULL值,可以处理一切意外情况..