扩展枚举范围
可能的重复:
Enumerable.Range 实现
我遇到了一个问题,我需要添加一个很长的值(Int64
) 到一个列表中,值为 600851475143,我想创建一个包含的 List
所有 int 都达到这个值,但是 Enumerable.Range
有一个限制,在 count 参数中,它只接受 int 值,因为我距离该值很远,我决定循环遍历列表和所有这些值,但我的系统很快就会耗尽内存,我该怎么办?
List<int64> lst = new List<int64>();
for (Int64 i = 3; i < 600851475143; i=i+2)
{
lst.Add(i);
}
谢谢
Possible Duplicate:
Enumerable.Range implementation
I ran into an issue where i need to add a very long value (Int64
) into a list, The value is 600851475143, i want to create a List<Int64>
that contains all the int upto this value, but Enumerable.Range
has a limitation that in the count parameter, it accept only int values, as i am far from that value, i decided to loop through the list and and all those values, but my system soons run out of memory, what should i do?
List<int64> lst = new List<int64>();
for (Int64 i = 3; i < 600851475143; i=i+2)
{
lst.Add(i);
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论中指出的,如此大的数组将需要大量的内存。例如,更好的选择是为自己创建一个枚举器来循环范围。开始查看此页面,了解如何: http://msdn.microsoft.com/ en-us/library/9k7k7cf0.aspx :-)
As pointed out in the comments, such a large array would require an enormous amount of memory. A better option would for instance be to create yourself an enumerator to loop over the range. Start looking at this page for how to: http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx :-)