All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
入门知识:动态网页PHP编程中字符串5个技巧_[PHP教程]
ASP.NET2.0服务器控件开发之实现事件_[Asp.Net教程]
aspx网页以HTML形式存储的几个方法_[Asp.Net教程]
数据库技巧之建立一个传表名参数的存储过程_[SQL,Server教程]
ASP.NET中自定义提示对话框_[Asp.Net教程]
visual c++在网页视图中的应用
PHP实例教程:PHP实现文件安全下载的程序_php资料_编程技术
ASP.NET,2.0中CSS不正常问题及解决_[Asp.Net教程]
PHP技巧:使用PHP制作动态网页过程中的五个技巧_[PHP教程]
ASP.NET,2.0中XSLT的使用_[Asp.Net教程]
Reading number is top 10 pictures
Breasts woman big set 2
陪睡门马睿菈自曝写真 称首拍大尺度照片1
Sora aoi on twitter1
In 2013 hercules Arnold classic2
职场回春术
Ashlynn Brooke show proud chest measurement2
The money of more than 100 countries and regions21
HongMenYan premiere XinLiangGong clairvoyant outfit PK YiFeiLiu2
Embarrassing things comic collection2
青春清纯美女大集合4
Download software ranking
Ashlynn Video5
Sora aoi, the nurse, uniform ,nursing assistant
Boxer vs Yellow3
Popkart Cracked versions Mobile phone games
Desire a peach blossom
虚拟机5.5.3版
Eclipse 4.2.2 For Win64
Tram sex maniac 2 (H) rar bag10
变速齿轮3.26
WebService在.NET中的实战应用教学视频 → 第2集
delv published in(发表于) 2014/1/10 6:28:59 Edit(编辑)
C#中ref和out的使用小结_[Asp.Net教程]

C#中ref和out的使用小结_[Asp.Net教程]

C#中ref和out的使用小结_[Asp.Net教程]

 ref是传递参数的地址,out是返回值,两者有一定的相同之处,不过也有不同点。

  使用ref前必须对变量赋值,out不用。

  out的函数会清空变量,即使变量已经赋值也不行,退出函数时所有out引用的变量都要赋值,ref引用的可以修改,也可以不修改。

  区别可以参看下面的代码:


using System;
class TestApp
{
 static void outTest(out int x, out int y)
 {//离开这个函数前,必须对x和y赋值,否则会报错。
  //y = x;
  //上面这行会报错,因为使用了out后,x和y都清空了,需要重新赋值,即使调用函数前赋过值也不行
  x = 1;
  y = 2;
 }
 static void refTest(ref int x, ref int y)
 {
  x = 1;
  y = x;
 }
 public static void Main()
 {
  //out test
  int a,b;
  //out使用前,变量可以不赋值
  outTest(out a, out b);
  Console.WriteLine("a={0};b={1}",a,b);
  int c=11,d=22;
  outTest(out c, out d);
  Console.WriteLine("c={0};d={1}",c,d);

  //ref test
  int m,n;
  //refTest(ref m, ref n);
  //上面这行会出错,ref使用前,变量必须赋值

  int o=11,p=22;
  refTest(ref o, ref p);
  Console.WriteLine("o={0};p={1}",o,p);
 }
}

来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.