谁能告诉我如何将Session分配给int []

编程入门 行业动态 更新时间:2024-10-19 21:30:11
本文介绍了谁能告诉我如何将Session分配给int []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

您好,我尝试检索到与int数组的会话,但是由于无法将类型为"System.Int32"的对象转换为类型为"System.Int32 []",因此出现错误'. 这就是我做的

Hi all I am trying to retrieve to session to an int array, but I am getting an error as Unable to cast object of type ''System.Int32'' to type ''System.Int32[]''. This is what I did

int[] year = (int[])Session["year"]; // For this I am getting that error DateTime[] dtStartPayPeriodDate = (DateTime[])Session["StartDates"]; DateTime[] dtEndPayPeriodDate = (DateTime[])Session["EndDates"];

对于其余的一切,它可以正常工作吗?任何人都可以告诉我出了什么问题.

for the remaining it works fine can any one tell what''s wrong

推荐答案

这是在告诉您在Session中只有一个int值.您需要做的是获取值并分别分配.一个简单的实现应如下所示: This is telling you that you only have a single int value in Session. What you need to do is retrieve the value and assign it separately. A simple implementation would look like this: int[] year = new int[] { (int)Session["year"] };

这不是我通常会做的事情,但它应该对您有用.

This isn''t something I would normally do, but it should work for you.

该会话包含类型为"int"的变量,您正尝试将其强制转换为"int []".因此它将不起作用. 更正后的代码如下: The session contains the variable of type ''int'' and you are trying to cast it to ''int []''. So it will not work. The corrected code is as follows: int year = Convert.ToInt32(Session["year"].ToString()); // corrected

您确定 Session["year"]

中存储的值是整数数组? 看起来该变量中的所有内容都是一个整数. 尝试以下操作:

is an array of Int? It looks like all you have in that variable is a single integer. Try this:

int year = int.Parse(Session["year"]);

更多推荐

谁能告诉我如何将Session分配给int []

本文发布于:2023-07-29 08:52:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239240.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:告诉我   谁能   如何将   int   Session

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!