请问一下用.net 怎么实现保存多个对象
请问一下用.net 怎么实现保存多个对象 --------------------编程问答-------------------- ??? --------------------编程问答-------------------- cache --------------------编程问答-------------------- 什么意思,想怎么保存 --------------------编程问答-------------------- 我现在有一个需求就是,用.NET实现,把前台用的提示信息都定义为常量,然后写一个方法供前台调用,我就想到把这些常量放到一个集合里,前台传过来一个code和我的KEY比较,要是一样,我就把它对应的提示信息返回给他,我是学JAVA的,但是我不会用.net写,请大家多多指教。 --------------------编程问答-------------------- Hashtable --------------------编程问答-------------------- hidden --------------------编程问答-------------------- 枚举好像比较适合你的需求啊 --------------------编程问答-------------------- Dictionary<Tkey,TValue> --------------------编程问答-------------------- 在appcode里加如一个新类,写一个方法类似下面public void alert(string key)
{
string msg ="";
if(key.equles("a"))
{
msg = "";
}
else if(key.equles("a"))
{.....
}
HttpContext.current.Response.write("<script>alert('"+msg+"')</script>");
} --------------------编程问答-------------------- 楼上的应该可以满足楼主 --------------------编程问答-------------------- 这是我用.net写的,
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
namespace OneDayClosing.Web.Test
{
public class MessageConstants
{
public static const String MESSAGE_SUCCESS = "file load success.";
public static const String MESSAGE_LONG = "filename too long";
public static Hashtable resourceTable = new Hashtable();
public static String getMessageByCode(String code) {
String text = "";
resourceTable.Add("MESSAGE_SUCCESS", "MESSAGE_SUCCESS");
resourceTable.Add("MESSAGE_LONG", "MESSAGE_LONG");
IDictionaryEnumerator messageEnumerator = resourceTable.GetEnumerator();
while (messageEnumerator.MoveNext())
{
if (code == null)
{
return text;
}
else if (code == messageEnumerator.Key)
{
text =messageEnumerator.Value;
return text;
}
}
return text;
}
}
}
然后我又在页面上写了一个按钮触发一个事件来调用的这个类,
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace OneDayClosing.Web.Test
{
public partial class messageConstants : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String mess = MessageConstants.MESSAGE_SUCCESS;
MessageConstants.getMessageByCode(mess);
}
}
}
但是它抱错说,
Error 1 The constant 'OneDayClosing.Web.Test.MessageConstants.MESSAGE_SUCCESS' cannot be marked static
请大虾们多多指教。
--------------------编程问答-------------------- 大侠们不是大虾们,呵呵,要是虾怕人给吃了
补充:.NET技术 , ASP.NET