Hashtable不工作! [英] Hashtable not working!

查看:61
本文介绍了Hashtable不工作!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了以下代码:



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Collections;

namespace ivycode.App_Classes
{

Hashtable objHT = new Hashtable();
database objDB = new database();
string sRetVal = ;

public class clsQuoteUs
{

}
}



现在问题是尽管包括System.Collections,我无法使用Hashtable objHT = new Hashtable();声明,因为它没有认识到。我正在研究一个Web应用程序,在参考文献中我尝试添加.dll但它没有被列入。



请帮助解决问题。



谢谢



IB

解决方案

您不能将变量放在命名空间中,您需要将它们放在类或方法中。



如果您想让这些变量全局可访问,请将它们放在静态类中 GlobalVariables

< pre lang =cs> 使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Collections;

namespace ivycode.App_Classes
{
public static class GlobalVariables
{
public static Hashtable objHT = new Hashtable();
public static 数据库objDB = new database();
public static string sRetVal = ;
}
}



要访问它们,请使用以下代码:

 GlobalVariables.sRetVal =   value; 



希望这有帮助。


I have written the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;

namespace ivycode.App_Classes
{
    
    Hashtable objHT = new Hashtable();
    database objDB = new database();
    string sRetVal = "";

    public class clsQuoteUs
    {

    }
}


Now the problem is despite of including System.Collections, I am not able to use Hashtable objHT = new Hashtable(); statement as it is not recognizing. I am working on a web application and in references i tried adding the .dll but it is not enlisted.

Please help resolve the problem.

Thanks

IB

解决方案

You can't put variables in a namespace, you need to put them in a class or method.

If you want to make these variables global accessible, put them in a static class GlobalVariables:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;

namespace ivycode.App_Classes
{
    public static class GlobalVariables
    {
        public static Hashtable objHT = new Hashtable();
        public static database objDB = new database();
        public static string sRetVal = "";
    }
}


And to access them, use this code for example:

GlobalVariables.sRetVal = "value";


Hope this helps.


这篇关于Hashtable不工作!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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