c#函数的参数类型
来源:互联网 发布:python caffe 编辑:程序博客网 时间:2024/05/21 09:21
参数类型主要包括两种
一、值类型
在使用值类型参数时,是把一个值传递给函数使用的一个变量。对函数中此变量的任何修改都不影响函数调用中指定的参数
二、引用类型
可以影响参数,引用类型的作用还是比较大。会在以后的实战项目中经常碰到,暂不多说,下面只给一个关于引用类型的例子
其中ref和out的区别在于out在主函数中不需赋值,ref一定要赋值
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class Program { static int IntTest(int i) { i *= 2; return i; } static void RefTest(ref int i) { i = 1; i = i * 2; Console.WriteLine("{0}", i); } static int MaxArray(int[] array ,out int index) { int max=array[0]; index=0; for (int i = 0; i<array.Length; i++) { if (max < array[i]) max = array[i]; index = i; } return max; } static void Main(string[] args) { #region//ref测试 int m= 1;//不用加ref在此必须给m赋值 Console.WriteLine("{0}", m); RefTest(ref m);//在此注意要添加ref Console.WriteLine("{0}", m); #endregion #region//int测试 int n = 1; Console.WriteLine("{0}", n); Console.WriteLine("{0}", IntTest(n)); Console.WriteLine("{0}", n); #endregion #region//out测试 int[] arry = { 1,2,3,4,5,6,7,7,7,7}; int index;//在此无须给index赋值,注意与ref的比较 Console.WriteLine("{0}", MaxArray(arry, out index)); Console.WriteLine("{0}", index);// #endregion Console.ReadKey(); } }}
最终的值为12212179(为节省空间,就这样写了)
- c#函数的参数类型
- C#的参数类型
- 函数参数的类型
- C# 引用类型作为函数参数时
- C# 引用类型作为函数参数时
- c#类型参数的约束
- 函数参数类型的定义
- 函数调用,C# 调用Dll中非托管C++代码时,函数参数的类型对照
- C#之控制台基础 函数的参数是一个函数,使用委托类型
- C#调用C++ dll 时,涉及到函数参数类型的转换,这里是C++和C#的类型对照表
- C#中调用C++的dll的参数为指针类型的导出函数
- C#中调用C++的dll的参数为指针类型的导出函数
- C#调用VC的DLL的接口函数参数类型转换一览表
- C#调用VC的DLL的接口函数参数类型转换一览表
- C#调用VC的DLL的接口函数参数类型转换一览表
- C#调用VC的DLL的接口函数参数类型转换一览表
- C#调用VC的DLL的接口函数参数类型转换一览表_蓝竹傲雪
- C#调用VC的DLL的接口函数参数类型转换一览表
- centos linux系统安全配置、php安全配置
- NPOI 函式庫(NPOI.dll)
- android 适配器Adpter的使用总结 之 BaseExpandableListAdapter
- 数据库连接池技术中dbcp、c3p0、jndi
- MySQL索引 聚集索引
- c#函数的参数类型
- 代码搜索引擎推荐
- C语言中strcpy,strcmp,strlen,strcat函数原型
- windowsMobiel 屏蔽右键
- 使用 Spring 更好地处理 Struts 动作(三种整合 Struts 应用程序与 Spring 的方式)
- android 适配器Adpter的使用总结 之 各种适配器中的方法
- 对于压缩文件的处理
- ExtJS 3 在Tab下加入Form 实例
- 读取文件方法