[英]Accessing list objects from another asp.net page
I create a list ... 我创建一个列表...
private static List<int[]> arrayList = new List<int[]>();
public static void Add(int Id, int Quantity)
{
int[] buying = new int[] {Id, Quantity};
arrayList.Add(buying);
}
Now ideally I want to access these list objects from another page, but its the first time I've really used lists and arrays so I don't know where to start? 现在,理想情况下,我想从另一个页面访问这些列表对象,但这是我第一次真正使用列表和数组,因此我不知道从哪里开始?
any pointers? 有指针吗?
Thanks 谢谢
Save the objects's state from one page in Session: 从会话的一页中保存对象的状态:
Session["arrayList"] = arrayList
Access it in another Page: 在另一个页面中访问它:
if(Session["arrayList"]!=null)
List<int[]> arrayList = Session["arrayList"] as List<int[]>;
1) Your List is private. 1)您的清单是私人的。 U must do it public 2) Where is this code located? U必须将其公开2)此代码位于何处?
You can expose another method like so 您可以公开这样的另一种方法
public static IEnumerable<int> MyArrayList()
{
return arrayList;
}
This way you can only read the elements in the next page. 这样,您只能阅读下一页中的元素。 If you want to add any elements then you can use your Add() method. 如果要添加任何元素,则可以使用Add()方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.