惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
P
Privacy & Cybersecurity Law Blog
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
Project Zero
Project Zero
L
LangChain Blog
N
News and Events Feed by Topic
博客园 - Franky
Last Week in AI
Last Week in AI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
月光博客
月光博客
博客园_首页
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
腾讯CDC
Latest news
Latest news
WordPress大学
WordPress大学
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
量子位
L
LINUX DO - 热门话题
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
L
Lohrmann on Cybersecurity
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
Security Latest
Security Latest
小众软件
小众软件
Cloudbric
Cloudbric
Hacker News: Ask HN
Hacker News: Ask HN
S
Secure Thoughts
雷峰网
雷峰网
T
Threat Research - Cisco Blogs
H
Hacker News: Front Page
IT之家
IT之家
Simon Willison's Weblog
Simon Willison's Weblog

博客园 - 流星啊。

vscode安装go所有插件 navicat15 for mysql激活 sql 循环语句几种方式 试用版SQL Server 2008 R2 提示评估期已过 常用SQL QQ web api Mysql数据库的分离和附加<转> Java字符串转换为日期和时间比较大小 Oracle中账户被锁定的解决方法 清除代码异味 EXT3.3在IE9上 , TreePanel click event 失效 在XP下配置自己的服务器IIS Extjs 树形设置选中 Window下删除SVN文件 GOF设计模式(转) ASCII表 博文阅读密码验证 - 博客园 查询最近10天要过生日的会员 Extjs中grid初始化时选中指定行的问题 - 流星啊。 - 博客园
C# 中ref out区别
流星啊。 · 2010-11-17 · via 博客园 - 流星啊。

1、使用ref型参数时,传入的参数必须先被初始化。对out而言,必须在方法中对其完成初始化。

2、使用ref和out时,在方法的参数和执行方法时,都要加Ref或Out关键字。以满足匹配。

3、out适合用在需要retrun多个返回值的地方,而ref则用在需要被调用的方法修改调用者的引用的时候。

在C#中,方法的参数传递有四种类型:传值(by value),传址(by reference),输出参数(by output),数组参数(by array)。

示例:

代码

static void Main(string[] args)
{
//outTest
int a, b; //没赋值
outTest(out a, out b);
Console.WriteLine(
"Out Test: a={0}, b={1}",a,b); //输出 a=10,b=20

int c=8,d=9; //赋值
outTest(out c,out d);
Console.WriteLine(
"Out Test: c={0}, d={1}", c, d);//输出 c=10,d=20//RefTest
int o, p;
// refTest(ref o, ref p); 错误,Ref 使用前变量必须赋值
o = 1; p = 2;
refTest(
ref o,ref p);
Console.WriteLine(
"Ref Test:o={0},p={1}", o, p); //输出 o=30,p=40

Console.ReadLine();
}
static void outTest(out int x,out int y)
{
//Console.WriteLine("befor out: x={0},y={1}",x,y); 报错,使用out后,x,y都被清空,需要重新赋值
x = 10;
y
= 20;
}
static void refTest(ref int x,ref int y)
{
Console.WriteLine(
"befor ref: x={0},y={1}", x, y); //输出 x=1,y=2
x = 30;
y
= 40;
}