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