请问这段VB的代码改成c#代码是怎样的? private void Page_Load( object sender,System.EventArgs e ){ DataBind();} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请问“ByVal sender”、“ByVal”是什么来的? ByVal是VB.Net里面的关键字“关键字指示参数可以按如下方式传递:被调用的过程或属性不能更改调用它的代码中参数的基础变量的值。” vb和c#中都有两种方式传递参数vb中:byval值传递,不能在过程中改变原值byref引用传递,可以在过程中改变原值c#中:默认是值传递,不需要声明引用传递需要声明例:使用 ref 和 out 传递数组:与所有的 out 参数一样,在使用数组类型的 out 参数前必须先为其赋值,即必须由接受方为其赋值。例如:public static void MyMethod(out int[] arr) { arr = new int[10]; // definite assignment of arr}与所有的 ref 参数一样,数组类型的 ref 参数必须由调用方明确赋值。因此不需要由接受方明确赋值。可以将数组类型的 ref 参数更改为调用的结果。例如,可以为数组赋以 null 值,或将其初始化为另一个数组。例如:public static void MyMethod(ref int[] arr) { arr = new int[10]; // arr initialized to a different array}下面的两个示例说明 out 和 ref 在将数组传递给方法上的用法差异。示例 1在此例中,在调用方(Main 方法)中声明数组 myArray,并在 FillArray 方法中初始化此数组。然后将数组元素返回调用方并显示。// cs_array_ref_and_out.csusing System; class TestOut { static public void FillArray(out int[] myArray) { // Initialize the array: myArray = new int[5] {1, 2, 3, 4, 5}; } static public void Main() { int[] myArray; // Initialization is not required // Pass the array to the callee using out: FillArray(out myArray); // Display the array elements: Console.WriteLine("Array elements are:"); for (int i=0; i < myArray.Length; i++) Console.WriteLine(myArray[i]); }}输出Array elements are:12345示例 2在此例中,在调用方(Main 方法)中初始化数组 myArray,并通过使用 ref 参数将其传递给 FillArray 方法。在 FillArray 方法中更新某些数组元素。然后将数组元素返回调用方并显示。// cs_array_ref_and_out2.csusing System; class TestRef { public static void FillArray(ref int[] arr) { // Create the array on demand: if (arr == null) arr = new int[10]; // Otherwise fill the array: arr[0] = 123; arr[4] = 1024; } static public void Main () { // Initialize the array: int[] myArray = {1,2,3,4,5}; // Pass the array using ref: FillArray(ref myArray); // Display the updated array: Console.WriteLine("Array elements are:"); for (int i = 0; i < myArray.Length; i++) Console.WriteLine(myArray[i]); }}输出Array elements are:1232341024 gridview导出 excel bt事件没反应!求解! 关于软件的数据保存问题 向高手请教一个反编辑的代码?? C#实现附件上传和下载的问题,急!各位帮帮忙!! winform如何实现图片的上一个下一个效果 winform如何获得用户控件里的控件值(急) c#中如何实现delphi那样: 可以直接在IDE环境上编写数据集的事件过程(如:afterInsert等) 如何获取刚刚插入数据库的记录的ID? 简单问题,关于循环 asp.net(C#)缓存问题~~~~急啊,求救 如何System.Windows.Forms.DataGrid继承他增加合计功能 简单问题,帮帮我
vb中:
byval值传递,不能在过程中改变原值
byref引用传递,可以在过程中改变原值
c#中:
默认是值传递,不需要声明
引用传递需要声明例:使用 ref 和 out 传递数组:
与所有的 out 参数一样,在使用数组类型的 out 参数前必须先为其赋值,即必须由接受方为其赋值。例如:public static void MyMethod(out int[] arr)
{
arr = new int[10]; // definite assignment of arr
}
与所有的 ref 参数一样,数组类型的 ref 参数必须由调用方明确赋值。因此不需要由接受方明确赋值。可以将数组类型的 ref 参数更改为调用的结果。例如,可以为数组赋以 null 值,或将其初始化为另一个数组。例如:public static void MyMethod(ref int[] arr)
{
arr = new int[10]; // arr initialized to a different array
}
下面的两个示例说明 out 和 ref 在将数组传递给方法上的用法差异。示例 1
在此例中,在调用方(Main 方法)中声明数组 myArray,并在 FillArray 方法中初始化此数组。然后将数组元素返回调用方并显示。// cs_array_ref_and_out.cs
using System;
class TestOut
{
static public void FillArray(out int[] myArray)
{
// Initialize the array:
myArray = new int[5] {1, 2, 3, 4, 5};
} static public void Main()
{
int[] myArray; // Initialization is not required // Pass the array to the callee using out:
FillArray(out myArray); // Display the array elements:
Console.WriteLine("Array elements are:");
for (int i=0; i < myArray.Length; i++)
Console.WriteLine(myArray[i]);
}
}
输出
Array elements are:
1
2
3
4
5
示例 2
在此例中,在调用方(Main 方法)中初始化数组 myArray,并通过使用 ref 参数将其传递给 FillArray 方法。在 FillArray 方法中更新某些数组元素。然后将数组元素返回调用方并显示。// cs_array_ref_and_out2.cs
using System;
class TestRef
{
public static void FillArray(ref int[] arr)
{
// Create the array on demand:
if (arr == null)
arr = new int[10];
// Otherwise fill the array:
arr[0] = 123;
arr[4] = 1024;
} static public void Main ()
{
// Initialize the array:
int[] myArray = {1,2,3,4,5}; // Pass the array using ref:
FillArray(ref myArray); // Display the updated array:
Console.WriteLine("Array elements are:");
for (int i = 0; i < myArray.Length; i++)
Console.WriteLine(myArray[i]);
}
}
输出
Array elements are:
123
2
3
4
1024