如何使用 C# 在单独的 aspx 页面中引用另一个类中的字段?

发布于 2024-09-15 04:12:11 字数 270 浏览 2 评论 0原文

我的 Default.aspx.cs 页面上的 Default 类中有一个二维双精度数组,如下所示:

protected Double[,] time;

在加载页面时,我已从数据库填充了该数组。现在,我想在另一个文件 (Diff.aspx.cs) 中引用该数组,以避免再次访问数据库。此外,数据以只读方式使用。


编辑:下面有一些有用的链接。我决定尝试隐藏的查询字符串/解析方法。如果有人有更直接的答案,请提出。感谢所有写信的人:D

I have a 2D array of doubles in my Default class on my Default.aspx.cs page, like so:

protected Double[,] time;

By the time the page loads, I have populated this array from a database. Now, I want to reference this array in another file (Diff.aspx.cs) to avoid visiting the database again. Also, the data is used in a read-only fashion.


EDIT: There were some helpful links below. I have decided to attempt the hidden querystring/parse method. If anyone has a more straightforward answer, please suggest it. Thanks to everyone who wrote :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

草莓味的萝莉 2024-09-22 04:12:11

奇怪的是,我认为您正在尝试将值(在您的情况下为数组)从一个页面传递到另一页面。您可以参考camilin87发布的链接。有几种方法可以做到这一点,例如会话状态、视图状态、查询字符串等。每个选项都有优点和缺点,最合适的选项取决于你的情况。您可以询问是否需要更多说明。

如果您使用的是 .NET 4.0,这里有一个直接链接。
http://msdn.microsoft.com/ en-us/library/6c3yckfw%28v=VS.100%29.aspx

Freakishly, I think you are trying to pass values (in your case, array) from one page to another page. You may refer to the link posted by camilin87. There are few ways to do this, like session state, viewstate, querystring, etc. There are pros and cons for each of the options, the most suitable option depends on your situation. You may ask if you need more clarification.

Here's a direct link for you if you are using .NET 4.0.
http://msdn.microsoft.com/en-us/library/6c3yckfw%28v=VS.100%29.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文