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

推荐订阅源

G
Google Developers Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Martin Fowler
Martin Fowler
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
IT之家
IT之家
云风的 BLOG
云风的 BLOG
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
博客园_首页
J
Java Code Geeks
C
Check Point Blog
I
InfoQ
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
D
Docker
U
Unit 42
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
GbyAI
GbyAI
N
Netflix TechBlog - Medium
T
Tailwind CSS Blog

博客园 - gyhanonline

Function Point in Vbscript Window API in QTP Simulate click event using widows API. Static Constructor A Go Set program A Go Set program About Inherit Code for Inter-process communicate Integrity Level Test for publish blog by word 2007 托管为什么安全 The usage of intellisense in Vs .net 2005 我的面试(七) 关于singlton的一些问题 我的面试(六) 我的面试(五) 我的面试(四) 我的面试(三) 我的面试(二)
我的面试(四)补充1
gyhanonline · 2007-09-20 · via 博客园 - gyhanonline

突然想起来前天面试时,考官问我out参数和ref参数的区别。我当时答的是out是出的,ref可以来回传参。也就是说out参数是进不来的,而ref是可以进来了。
今天写代码试了试。从新整理一下关于out和ref的区别。

static void Function1(out int outParameter, ref int refParameter)
        {
            outParameter += 1;
            refParameter += 2;
        }
如果这样去写方法,编译是不通过的,系统会提示要为out参数赋初值。
         呵呵,其实就是outParameter 无论原来是啥,这一赋初值不就给覆盖了吗?也就是所谓的“传不进来”,而ref参数则没有“赋初值”的要求。简单的说就是“传进来”啥就用啥继续干活。
        那么out,ref参数个认为是在方法要求有多个返回值时使用,如果只要一个返回值时大可以用return。不要用out,ref搞得那么复杂。
         嘿嘿,基础的基础。大家认为关于out,ref还有啥,不妨说说哈。