代码大体如下:
class c1
{
public static void stoiarr(string s, ref int[] a)
{
...
ArrayList al = new ArrayList();
...
a = new int[al.count]; // 我在这里给数组申请空间,等到函数结束后是否还能保留
// 这部分空间。这个算不算非法的引用。不过这段代码运行
// 正常,没出现什么错误。
...
}
}class c2
{
public static void Main()
{
c1 li = new c1();
string s = "1,4-7,11";
int[] a = null;
libin.SToIntArray(s, ref a); // 给定的字符串经过函数处理后通过整型数组a输出。在这里
// 数组a经过函数处理后应该包含以下值{1,4,5,6,7,11}
foreach (int i in a)
{
System.Console.WriteLine(i);
}
System.Console.ReadLine();
}
}我这样做对吗?今后的运行过程中是否会蹦错呢?
以前用c++,最近初学c#,对这种问题很不明白。
大家来帮帮我吧。
class c1
{
public static void stoiarr(string s, ref int[] a)
{
...
ArrayList al = new ArrayList();
...
a = new int[al.count]; // 我在这里给数组申请空间,等到函数结束后是否还能保留
// 这部分空间。这个算不算非法的引用。不过这段代码运行
// 正常,没出现什么错误。
...
}
}class c2
{
public static void Main()
{
c1 li = new c1();
string s = "1,4-7,11";
int[] a = null;
libin.SToIntArray(s, ref a); // 给定的字符串经过函数处理后通过整型数组a输出。在这里
// 数组a经过函数处理后应该包含以下值{1,4,5,6,7,11}
foreach (int i in a)
{
System.Console.WriteLine(i);
}
System.Console.ReadLine();
}
}我这样做对吗?今后的运行过程中是否会蹦错呢?
以前用c++,最近初学c#,对这种问题很不明白。
大家来帮帮我吧。
解决方案 »
- 关于前台页面调用COM组件
- webbrowser 滚动条位置问题?
- 哪有一本好的介绍常用类库的书,其中只介绍普通开发者常用的类,因为很多类可能对于信息系统开发者永远也用不到,却都集在一起,很不利于查阅和掌握类库。
- 两个gridview间的事件
- 怎么把购物车中的信息写入数据库,会面向对象的来。
- 如何同时使用两个时间触发事件?
- 200分求3问题 -- 顺预祝大家元旦快乐!
- c# 中 多线程与事件处理器协同工作的问题??????
- 共同参与--完美 数据迁移系统 的解决方案!!参与者赠送所有最终资料!
- 求 C# 下面 MySql 的驱动,谢谢
- using System.Management
- vs.net打包winform程序,添加桌面快捷方式问题
out和ref的为一区别就是在编译时 ref必须要赋值 但是你ref赋值为null,指向空地址,调用人人用起来容易出错
所以用out好一些