class Program
{
/*ref是有进有出,out是只出不进*/
static void Main(string[] args)
{
/*作为Out参数传递 传递前可以不初始化*/
string outString = "This is the outString value";
Console.WriteLine(outString);
outMethod(out outString);
Console.WriteLine(outString);
/*作为Ref参数传递 传递前必须初始化*/
string refString = "This is the refString value";
Console.WriteLine(refString);
refMethod(ref refString);
Console.WriteLine(refString);
Console.ReadLine();
}
static bool outMethod(out string str)
{
/*作为Out参数传递 传递到方法体后 参数被清空*/
//Console.WriteLine(str); Use of unassigned out parameter 'str'
/*作为Out参数传递 值必须在方法体内赋值*/
/*作为Out参数传递 返回前值必须初始化*/
str = "This is the new outString value";
return true;
}
static bool refMethod(ref string str)
{
Console.WriteLine(str);
/*作为Ref参数传递 返回前值可以不初始化*/
return true;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有