class Program
{
static void Main(string[] args)
{
//普通 :
int k1 = ;
int result1 = Test1(k1, );
Console.WriteLine("/*普通:*/");
Console.WriteLine(result1);
Console.WriteLine(k1); //ref :
//用法: 参数要用 ref 一起传递,并且是可以赋值的变量,ref 变量要先赋值
int k2 = ;
int result2 = Test2(ref k2, );
Console.WriteLine("/*ref:*/");
Console.WriteLine(result2);
Console.WriteLine(k2); //out :
//用法: 参数要用 out 一起传递,并且是可以赋值的变量,out 变量不用先赋值(只定义即可)
int k3;
Console.WriteLine("/*out:*/");
int result3 = Test3(out k3, );
Console.WriteLine(result3);
Console.WriteLine(k3);
} /// <summary>
/// 普通
/// </summary>
public static int Test1(int k, int p)
{
k++;
return k + p;
} /// <summary>
/// ref
/// </summary>
public static int Test2(ref int k, int p)
{
k++;
return k + p;
} /// <summary>
/// out
/// </summary>
public static int Test3(out int k, int p)
{
//out 未赋值的变量不能使用,所以在方法内部赋值。
k = + ;
return k + p;
}
}

运行结果:

最新文章

  1. 兄弟连javascript学习笔记
  2. 使用 Laravel 前的准备工作
  3. 在Python中调用glutInit遇到OpenGL.error.NullFunctionError的解决方法
  4. 整理 iOS 9 适配中出现的坑(图文)(转)
  5. MVP -----个人理解与示例(android例子 实现)
  6. BZOJ4060 : [Cerc2012]Word equations
  7. JavaScript要点(十七) Math 对象
  8. 5 个在 Linux 中管理文件类型和系统时间的有用命令
  9. PL/SQL:使用pragma restrict_references限制包权限
  10. Two ways to create file using &#39;doc&#39;.
  11. FeatureClass Copy
  12. 淘淘商城_day11_课堂笔记
  13. UE4利用Save Game创建全局变量
  14. flask下载excel
  15. win10安装配置nodejs
  16. 【转】C++标准转换运算符const_cast
  17. Python Matplot中文显示完美解决方案
  18. Windows操作系统下的MySQL主从复制及读写分离
  19. 基于Sql Server 2008的分布式数据库的实践
  20. spark2.1.1创建Pipeline

热门文章

  1. sql查询练习
  2. Mac上svn报错解决方案
  3. [Leetcode 771]宝石和石子 Jewels and Stones HashSet简单应用
  4. C语言实现Winsocket网络传输数据时乱码问题
  5. LeetCode 695 岛屿的最大面积
  6. mkpasswd命令
  7. windows下telnet不是内部或外部命令
  8. BiLstm原理
  9. binary and out mode to open a file
  10. day 10 函数入门