C#的引用
来源:互联网 发布:大数据时时彩在线计划 编辑:程序博客网 时间:2024/06/06 02:21
ref相当于C/C++的引用(&)
The ref keyword causes arguments to be passed by reference. The effect is that any changes to the parameter in the method will be reflected in that variable when control passes back to the calling method.
举例如下:
class RefExample
{
static void Method(ref int i)
{
// Rest the mouse pointer over i to verify that it is an int.
// The following statement would cause a compiler error if i
// were boxed as an object.
i = i + 44;
}
static void Main()
{
int val = 1;
Method(ref val);
Console.WriteLine(val);
// Output: 45
}
}
out相当于ref,但有所不同,ref使用时变量必须初始化,而out不必。
The out keyword causes arguments to be passed by reference. This is similar to the ref keyword, except that ref requires that the variable be initialized before being passed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword. For example:
class OutExample
{
static void Method(out int i)
{
i = 44;
}
static void Main()
{
int value;
Method(out value);
// value is now 44
}
}
呵呵,这给我们一个函数返回多值带来了方便,如要使用指针可使用关键字unsafe即可像C/C++运行指针了...
- C#的引用类型
- C#的引用
- C#引用的删除
- C# 引用的实质
- C#委托的引用
- C#的引用(ref)参数
- c#引用javawebservice的问题
- C#的显示引用转换
- C#引用JQuery的步骤
- C#引用JQuery的步骤
- C#中引用的用法
- C#引用JQuery的步骤
- C#的引用类型 -3
- c# 关于json 的引用
- C# 引用
- C# 强引用与弱引用的区别
- C#中的类的“引用字段”和“非引用字段”
- C#中 值引用和对象引用的区别
- FOR ALL ENTRIES vs DB2 JOIN
- LINUX变WIN7 Win2-7Pack_v6.0_Multilang_Aero
- LINUX变WIN7 Win2-7Pack_v6.0_Multilang_Aero
- 决不要重新定义继承而来的缺省参数值
- zookeeper安装和应用场合(名字,配置,锁,队列,集群管理)
- C#的引用
- sap去除后缀0方法
- windows系统如何设置应用程序崩溃自动内存转储
- 闲置小U盘变身最强大路由器~!
- C++学习总结_析构函数
- kernel hacker’s guide to git
- polymorphism
- ubuntu eclipse源安装
- solaris系统的版本和位数以及pkgadd,pkginfo,pkgrm