如何在asp.net中的页面加载中编写namescape和类 [英] how to write namescape and class in pageload in asp.net

查看:70
本文介绍了如何在asp.net中的页面加载中编写namescape和类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在pageload中使用一个类,我不想将namescape声明为
使用AppDAL;相反,我想在页面加载事件中使用它.

hi i want a use a class in the pageload,i dont want to declare namescape as
using AppDAL; at the top of the page instead i want to use it in the page load event.

using( AppDAL.AssetCardDAL obj = new AppDAL.AssetCardDAL())
           {

              // List<Contact> contacts = manager.GetContacts(int.Parse(contextKey), prefixText, count);
               //foreach (Contact c in contacts)
               //{
               //    items.Add(AutoCompleteExtender.CreateAutoCompleteItem(c.FullName, serializer.Serialize(c)));
               //}

               return items.ToArray();
           }



但这给了我错误,因为



but it is giving me error as

AppDAL.AssetCardDAL type used in a using statement must be implicitly convertible to   System.IDisposable 

推荐答案

继承IDisposible interface,可以在using块中使用.因为在完成使用块的任务后,它用来调用GC的Dispose Method.像这样创建AssetCardDAL 类:
The class which inherits IDisposible interface, can be used in using block. Because after completing the task in using block it used to call the Dispose Method of GC. Create the AssetCardDAL class like this:
public class AssetCardDAL : IDisposible
{
     //Your contents goes here
} 



您也可以在此类中覆盖Dispose 方法.


--Amit



You can also override the Dispose method here in this class.


--Amit


这篇关于如何在asp.net中的页面加载中编写namescape和类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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