C#若不加限制传值时自带的类型为值传递,自创的类型为引用传递

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication3
{
class AA
{
string s;
}
class Program
{
static void change(string s)
{
s = "";
}
static void Main(string[] args)
{
string s = "";
change(s);
Console.WriteLine(s);
}
}
}

输出 123

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication3
{
class AA
{
public string s;
public AA()
{
s = "";
}
}
class Program
{
static void change(AA t)
{
t.s = "";
}
static void Main(string[] args)
{
AA t = new AA();
Console.WriteLine(t.s);
change(t);
Console.WriteLine(t.s);
}
}
}

输出
123

000


可以指定为ref/out传值(函数声明和函数调用时都要加这个关键字)

其区别:

  ref必须要在调用前初始化,out必须在函数内初始化(不初始化前函数内不能使用)

最新文章

  1. SQL Server 进制转换函数
  2. C++ Programming language读书笔记
  3. One Time Auth
  4. java网络编程之UDP通讯
  5. Linux源码安装mysql步骤
  6. A Knight's Journey 分类: dfs 2015-05-03 14:51 23人阅读 评论(0) 收藏
  7. Hibernate 系列教程9-自关联
  8. Android ListView Adapter的getItemViewType和getViewTypeCount多种布局
  9. LoadRunner菜鸟入门学习笔记
  10. mac安装破解的Navicat
  11. PHP 截取字符串乱码的解决方案
  12. 原本在滴滴只负责批100万元以上开支的Leslie决定,ofo所有30万元以上的开支都要由她亲自过目。那段时间,他“天天晚上12点才下班,眼睛都熬红了”
  13. CentOS7搭建elasticsearch集群
  14. JAVAEE——BOS物流项目14:Linux部署(安装jdk、tomcat、mySQL)和扩展资料
  15. rsync + inotify 数据实时同步
  16. 【转】2012年6月25 – 某欧美上市企业PHP工程师最新面试题
  17. Nubia Z5S官方4.4 UI2.0音频Audio部分简单分析(也适用于其它8974/8064机型)以及降低破音出现几率的方法
  18. A4纸网页打印 html网页页面的宽度设置成多少
  19. Json-转自菜鸟教程
  20. Csharp:字符串操作

热门文章

  1. 搭建hadoop2.6.0集群环境
  2. 使用SQL除掉文本中特殊的ascll字符比如Enter,Tab,空格键
  3. zip命令的用法
  4. C 小写字母编程大写并输出
  5. epoll函数及三种I/O复用函数的对比
  6. github三大步骤
  7. 智能卡 ATR解析
  8. 初识Mybatis框架,实现增删改查等操作
  9. 【转】Windows 7/8/8.1 硬盘安装法实现 ubuntu 14.04 双系统
  10. bzoj 1193