的varibale我有一类constractor这样缓存在构造函数C#
public class product_new : NK.Objects._product_new
{
private int Count_Per_Page;
public product_new(int count_per_page)
{
this.Count_Per_Page = count_per_page;
}
public int CountOP///////count of pages
{
get
{
return number_of_pages(Count_Per_Page);
}
}
你看到CountOP是返回一个int值,它是连接到SQL数据库返回该值。
private int number_of_pages(int tedad_per_pages)
{
return Q.Get_Back_Number_Of_Pages(
tedad_per_pages,
tbl_name,
"",
new Queries.Cmd_Parameters());
}
在如果从这个类CountOP没有改变,但功能NUMBER_OF_PAGES创建对象几个时间被释放,并连接到SQL数据库。
我该如何缓存这个变量?
你的问题会容易得多,如果你阅读” d遵循常规的.NET命名约定。 –
在您的代码中添加以下行:private static字典 numberOfPages = new词典();然后在你的方法中使用numberOfPages“number_of_pages”。 –