问题列表 - 第23318页

使用foreach循环

我打破的代码用于循环,而无需使用断裂等我为给定循环时below.And 是1或2或3或任何其他人,但如果条件为真,则环将被终止,因为如果条件为将5 true.And所以NO需要休息的需要there.Beacause我不想用休息.我已经做了这样的工作here.It.

int myCondition=0;
bool flag=false;
for(int i=0;i<5;i++)
{
   if(myCondition==0)
   {
       flag=true;
   }
   if(flag)
       i=5;
}
Run Code Online (Sandbox Code Playgroud)

但现在我想用foreach循环,在这种循环时,一些条件为真,那么我想打破foreach循环 code.So我该怎么办这里打破foreach循环的代码,而无需使用休息?就像在上面的for循环中一样,当条件为真时,我将i初始化为5.在foreach循环中,任何类似的东西都要做以避免中断.

.net c# foreach for-loop winforms

0
推荐指数
2
解决办法
331
查看次数

编译LaTex bib源码

我正在Latex中写论文,我在自己的论文中有参考文献.bib文件如下所示

@Article{xxx,
  author =       "D.A. Reinhard",
  title =        "Case Study",
  year =         "1985",
}
Run Code Online (Sandbox Code Playgroud)

我在主文档中引用它们〜\ cite {xxx}

当我编译然后主文件:pdflatex main.tex比它显示问号而不是对参考书目的正确引用.我还需要自己编译bib源吗?如果是的话,有人可以告诉我Linux的命令

非常感谢!

latex bibtex citations pdflatex

61
推荐指数
4
解决办法
10万
查看次数

Python:类型检查所需的循环导入

首先:我知道已经有很多关于循环进口主题的问题和答案.

答案或多或少是:"正确设计模块/类结构,您不需要循环导入".那是真实的.我努力为我当前的项目做一个合适的设计,我认为我是成功的.

但我的具体问题如下:我需要在模块中进行类型检查,该模块已由包含要检查的类的模块导入.但这会引发导入错误.

像这样:

foo.py:

from bar import Bar

class Foo(object):

    def __init__(self):
        self.__bar = Bar(self)
Run Code Online (Sandbox Code Playgroud)

bar.py:

from foo import Foo

class Bar(object):

    def __init__(self, arg_instance_of_foo):
        if not isinstance(arg_instance_of_foo, Foo):
            raise TypeError()
Run Code Online (Sandbox Code Playgroud)

解决方案1:如果我修改它以通过字符串比较检查类型,它将起作用.但我真的不喜欢这个解决方案(对于简单的类型检查,字符串比较相当昂贵,并且在重构时可能会遇到问题).

bar_modified.py:

from foo import Foo

class Bar(object):

    def __init__(self, arg_instance_of_foo):
        if not arg_instance_of_foo.__class__.__name__ == "Foo":
            raise TypeError()
Run Code Online (Sandbox Code Playgroud)

解决方案2:我也可以将这两个类打包成一个模块.但我的项目有许多不同的类,如"Bar"示例,我想将它们分成不同的模块文件.

在我自己的2个解决方案对我来说没有选择之前:有没有人为这个问题找到更好的解决方案?

python import circular-dependency

8
推荐指数
2
解决办法
2009
查看次数

是否有(简单)方法来获取Lua表的内存使用?

我想知道Lua表使用了多少内存 - 没有遍历表内容并计算使用量.是否有Lua 5.1功能或第三方库可以帮助解决这个问题.

lua memory-management lua-table

5
推荐指数
1
解决办法
7769
查看次数

在Windows中隐藏Linux隐藏文件

是否可以在Windows中隐藏Linux隐藏文件(.*文件).

通过更改Windows中的文件属性来显式隐藏文件在Linux中有任何影响吗?

谢谢

基兰

linux windows file windows-vista

6
推荐指数
2
解决办法
5871
查看次数

加速PostgreSQL查询,其中数据在两个日期之间

我有一个大表(> 50米行),其中包含一些带有ID和时间戳的数据:

id, timestamp, data1, ..., dataN
Run Code Online (Sandbox Code Playgroud)

...打开多列索引(id, timestamp).

我需要查询表以选择具有特定ID的所有行,其中时间戳在两个日期之间,我目前正在使用:

SELECT * FROM mytable WHERE id = x AND timestamp BETWEEN y AND z
Run Code Online (Sandbox Code Playgroud)

目前在高端机器上需要2分钟(2x 3Ghz双核Xeons w/HT,16GB RAM,RAID 0中2x 1TB驱动器),我真的很想加速它.

我发现这个提示建议使用空间索引,但它提供的示例是IP地址.然而,速度增加(436s到3s)令人印象深刻.

我如何使用时间戳?

sql postgresql performance spatial-index

6
推荐指数
2
解决办法
1万
查看次数

同时关闭几个android活动

在我的应用程序中,您可以浏览多个活动,直到活动堆栈非常深.

我们希望每个Activity上都有一个按钮,可以直接返回主菜单 - 即从第一个弹出除了第一个活动之外的所有活动.

我把按钮放在一个View中,我可以很容易地把它放在应用程序中的每个Activity上,但是我无法弄清楚如何一举关闭几个Activity.

(如果可能的话,如果View可以计算出自己关闭多少个活动就好了 - 也就是说检测它自己的Activity有多深.)

android

7
推荐指数
1
解决办法
8170
查看次数

Emacs压痕难度

我真的想切换到emacs,但学习设置环境真的很痛苦.每个人都说它值得,所以我继续说.

我希望我的c代码以这种方式实现:

if(asdf)
{
    asdr = 1;
}
Run Code Online (Sandbox Code Playgroud)

根据当前的标准(我知道,不要让我开始),可能是:

if(asdf) {
    asdr = 1;
}
Run Code Online (Sandbox Code Playgroud)

我似乎无法将缩进大小从2更改,它总是看起来像GNU标准:

if(asdf)
  {
    asdr = 1;
  }
Run Code Online (Sandbox Code Playgroud)

,我不喜欢.这是我在.emacs中添加的内容:

; Warn in C for while();, if(x=0), ...
(global-cwarn-mode 1)

; no electric mode in c
(c-toggle-electric-state -1)
; indent the current line only if the cursor is at the beginning of the line
(setq-default c-tab-always-indent nil)
(setq-default c-indent-level 4)
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(setq-default c-basic-offset 4)
(setq-default c-basic-indent 4)
; These commands I read …
Run Code Online (Sandbox Code Playgroud)

emacs indentation

8
推荐指数
3
解决办法
1万
查看次数

在c ++ builder中编译c ++的问题

我为大学任务编写了一个C++程序.我在我的Mac上运行了Netbeans 6.8,代码运行顺畅,没有警告,错误或问题/错误.但是,当使用CodeGear RAD Studio 2009(C++ Builder)在Windows计算机上进行编译和运行时,会出现几个错误.

[BCC32 Error] main.cpp(51): E2094 'operator<<' not implemented in type 'ostream' for arguments of type 'string'
[BCC32 Error] main.cpp(62): E2093 'operator==' not implemented in type 'string' for arguments of the same type
[BCC32 Error] main.cpp(67): E2093 'operator==' not implemented in type 'string' for arguments of the same type
[BCC32 Error] main.cpp(112): E2093 'operator==' not implemented in type 'string' for arguments of the same type
[BCC32 Error] main.cpp(121): E2094 'operator<<' not implemented in type 'ostream' for …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors c++builder

1
推荐指数
1
解决办法
4100
查看次数

在配置文件中存储SQL查询?

关于在配置文件中存储SQL查询的每个人的意见的一般性问题?

这只是另一辆自行车棚吗?

干杯,本

sql database configuration

5
推荐指数
1
解决办法
1487
查看次数