87,920
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace AjaxTest
{
public partial class 变量引用测试 : System.Web.UI.Page
{
public void destory(ref Test t)
{
t.a = 2;
t = null;
}
public void destory(Test t)
{
t.a = 2;
t = null;
}
protected void Page_Load(object sender, EventArgs e)
{
Test test1 = new Test();
Test test2 = new Test();
destory(test1);
destory(ref test2);
this.div1.InnerText = test1.a.ToString();//显示2
if (test2!=null)//test2=null
{
this.div2.InnerText = test1.a.ToString();
}
}
}
public class Test
{
public int a = 1;
}
}
var obj = {
name: "test"
}
function test1(o){
o.name = "test1";
}
function test2(o){
o.name = "test2";
o = null;
}
alert(obj.name); // test
test1(obj);
alert(obj.name); // test1
test2(obj);
alert(obj.name); // test2
obj = null;
alert(obj.name); // exception: obj is null