如何通过页面作为参考参数的函数 [英] How to pass Page as ref parameter to a function

查看:75
本文介绍了如何通过页面作为参考参数的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我怎么能PAAS页为参考参数的函数

这就是我想要做的。


 
  公共部分类主页:System.Web.UI.Page
{
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        如果(!SetupUserPermission.isSessionExpired())
        {
            字符串userid =会话[用户ID]的ToString()。
            SetupUserPermission.SetupUserRights(REF this.Page,Convert.ToInt32(用户ID));
        }
    }
}
 


解决方案

您不能在C#中引用传递属性。你为什么想通过引用在此情况下通过网页?

在VB中你可以的通过引用传递性,以及在这种情况下,相当于将是:

 网​​页TMP =页;
SetupUserPermission.SetupUserRights(REF TMP,Convert.ToInt32(用户ID));
页= tmp目录;

您真的确定要这么做?

我怀疑你真的不希望通过引用传递它,你只是稍微困惑参数的传递。请参见我的话题文章以了解更多信息。

I would like to know how Can I paas Page as Ref Parameter to a function

This is what I want to do

 
  public partial class HomePage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!SetupUserPermission.isSessionExpired())
        {
            string UserId = Session["UserId"].ToString();
            SetupUserPermission.SetupUserRights(ref this.Page, Convert.ToInt32(UserId));
        }


    }
}
 

解决方案

You can't pass a property by reference in C#. Why do you want to pass Page by reference in this case?

In VB you can pass a property by reference, and the equivalent in this case would be:

Page tmp = Page;
SetupUserPermission.SetupUserRights(ref tmp, Convert.ToInt32(UserId));
Page = tmp;

Are you really sure you want to do that?

I suspect you don't really want to pass it by reference, and you're just slightly confused about parameter passing. See my article on the topic for more information.

这篇关于如何通过页面作为参考参数的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆