我有一个基本的问题,可能是这么明显,但由于某种原因,我似乎无法成功安装和使用代码合同.
我从MSDN下载了软件包,按照在线文档安装了它,但我仍然收到以下代码语句的IDE警告:
Contract.Requires(inputParameter != "");
IDE警告是:
"跳过方法调用.编译器不会生成方法调用,因为该方法是有条件的,或者是没有实现的部分方法"
在启用代码合同的过程中我遗漏了什么?我正在使用VS2010 Ultimate SP1
请考虑以下代码:
class foo
{
public:
foo(){}
~foo(){}
void done() { delete this;}
private:
int x;
};
Run Code Online (Sandbox Code Playgroud)
在以下两个选项中发生了什么(并且有效吗?):
选项1:
void main()
{
foo* a = new foo();
a->done();
delete a;
}
Run Code Online (Sandbox Code Playgroud)
选项2:
void main()
{
foo a;
a.done();
}
Run Code Online (Sandbox Code Playgroud)
delete a;选项1中的第二个语句是否会导致异常或堆损坏?
option2会导致异常或堆损坏吗?
我正在使用Excel应用程序SheetChange事件来捕获我的Excel应用程序表中的任何更改.如果用户只修改了1个单元格,则可以通过以下方式检索单元格坐标:
void CellsChange(object Sh, Excel.Range Target)
{
....
string changedCell = Target.get_Address(Missing.Value, Missing.Value, Excel.XlReferenceStyle.xlA1, Missing.Value, Missing.Value);
....
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,典型的返回值是"$ C $ 11".
但是如果用户通过突出显示多个单元格来修改一系列单元格,并使用shift-enter以相同的值填充整个范围,则返回的字符串可以是:"$ C $ 11:$ K $ 11"(表示9个单元格连续变化).
我如何迭代抛出范围?获取foreach或for循环中的每个单元格坐标和值.我试过以下......
for (int i = 0; i < Target.Count; i++)
{
Excel.Range r = Target.Item[i];
MessageBox.Show(Convert.ToString(r.Value2));
}
Run Code Online (Sandbox Code Playgroud)
但是这段代码并没有给我原始范围单元格的新值.我也没有遵循Target.Item逻辑 - 它是基于零的数组还是一个基于数组的数组.在几次尝试中,看起来Item数组是整个单元格范围,形成为数组(因此也可以使用Item [0],这是突出显示范围左侧的一个单元格).
有没有人有更多使用Range对象和/或上述事件的经验?
谢谢
我有一个C++代码,我正在尝试迁移到C#.在那里,在C++上,我使用以下宏定义进行调试.
#define CODE_LOCATION(FILE_NAME, LINE_NUM, FUNC_NAME) LINE_NUM, FILE_NAME, FUNC_NAME
#define __CODE_LOCATION__ CODE_LOCATION(__FILE__, __LINE__, __FUNCTION__)
Run Code Online (Sandbox Code Playgroud)
C#中是否有类似的结构?我知道C#中没有宏,但有没有其他方法可以在执行期间获取当前文件,行和函数值?
我有一个字符串列表 (~400K),其中最长的字符串有~220 个字符。字符串用“.”表示对象的路径 作为分隔符。
我正在尝试构建一个自动完成功能,允许用户快速从列表中选择对象,而不是输入其完整路径。
自动完成功能基于根据用户输入过滤数据库。
我尝试了以下方法。
使用filter- 基准测试为 ~0.8 秒
database = list()
database.append("path.to.first.object")
database.append("path.to.first.some.object.of.mine")
....
database.append("path.to.last.object") # ~430K items
partial_name = "som"
filtered_list = list(filter(lambda x: partial_name in x, database))
Run Code Online (Sandbox Code Playgroud)regex方法 - 基准为 ~0.15 秒
regex = re.compile(r"{0}".format(partial_name))
filtered_list = list(filter(regex.search, database))
Run Code Online (Sandbox Code Playgroud)以上预计只会产生path.to.first.some.object.of.mine对象
我还考虑了Trie数据结构,但这个不支持“正则表达式”类型的过滤。
有没有更快的方法来过滤字符串?
我有一个tkinter包含ttk.treeview小部件的 python应用程序。
小部件显示在具有特定扩展名的特定目录树上找到的文件列表 - 使用tt.treeview小部件构建这很简单。
有一个请求启用树的“即时”过滤 - 例如,用户输入Entry某个字符串,当他/她输入时,树删除到目前为止与输入的字符串不匹配的元素。
我正在浏览Treeview文档,尝试了detach和reattach方法,但没有运气。
detach确实从树中删除了不匹配的元素,但是如果用户点击Backspace,我将无法再在树上正确迭代以恢复那些分离的元素,因为get_children方法不会返回它们。
def filter_tree(self):
search_by = self.search_entry.get()
self.tree_detach_leaf_by_regex(self.current_loaded_folder, search_by, "")
def tree_detach_leaf_by_regex(self, root, regex, parent):
if self.treeview.get_children(root):
for child in self.treeview.get_children(root):
self.tree_detach_leaf_by_regex(child, regex, root)
else:
if not re.match(regex, self.treeview.item(root)["text"]):
self.elements_index_within_parent[root] = self.treeview.index(root)
self.elements_parents[parent] = 1
self.treeview.detach(root)
else:
self.treeview.reattach(root, parent, self.elements_index_within_parent[root])
Run Code Online (Sandbox Code Playgroud)
期待阅读您的建议。
我使用 c++ 程序使用 opencv 2.1 进行图像处理。该程序具有以下包含文件:
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <math.h>
#include <string.h>
Run Code Online (Sandbox Code Playgroud)
但在调试程序后,我收到错误消息:
致命错误 C1083:无法打开包含文件:'opencv2/core/core.hpp':没有这样的文件或目录。
这是相同imgproc.hpp和highgui.hpp后,我改变了 #include "opencv2/highgui/highgui.hpp"对#include <highgui.h>和错误解决。
但是我找不到imgproc.hpp和highgui.hpp的解决方案,并且opencv 文件夹中没有名为imgproc.hpp和highgui.hpp的文件。
我该如何解决这个错误?
我正在学习正则表达式.我对这个例子有些怀疑:
我想在名称中找到所有带有常规扩展名的文件.这有效:
ls | grep '\.[[:lower:]][[:lower:]][[:lower:]]$'
Run Code Online (Sandbox Code Playgroud)
但这不是:
ls | grep '\.[[:lower:]]{3}$'
Run Code Online (Sandbox Code Playgroud)
据我所知,{n}迭代元字符导致与具有{n}前一个字符的确切出现的模式匹配.它不适用于POSIX类吗?或者我在这里犯了一些愚蠢的错误?
我尝试ttk.Combobox使用传统方式修改小部件字体
text_font = ('Courier New', '10')
mycombobox = Combobox(font = text_font)
mycombobox.pack()
Run Code Online (Sandbox Code Playgroud)
但字体并没有真正改变...
我也尝试使用ttk.Style但又没有任何反应......
text_font = ('Courier New', '10')
ttk_style = ttk.Style()
ttk_style.configure('App.TCombobox', font=text_font)
mycombobox = Combobox(style = "App.TCombobox")
mycombobox.pack()
Run Code Online (Sandbox Code Playgroud)
有没有办法控制字体?我想更改Entry和ListBox字体
我正在优化我们的调试打印设施(类)。该类大致简单,具有全局“启用”布尔值和PrineDebug例程。
我正在研究该方法在“禁用”模式下的性能PrintDebug,尝试创建一个在不需要调试打印的情况下对运行时影响较小的框架。
在探索过程中,我发现了以下结果,这让我感到惊讶,我想知道我在这里错过了什么?
public class Profiler
{
private bool isDebug = false;
public void PrineDebug(string message)
{
if (isDebug)
{
Console.WriteLine(message);
}
}
}
[MemoryDiagnoser]
public class ProfilerBench
{
private Profiler profiler = new Profiler();
private int five = 5;
private int six = 6;
[Benchmark]
public void DebugPrintConcat()
{
profiler.PrineDebug("sometext_" + five + "_" + six);
}
[Benchmark]
public void DebugPrintInterpolated()
{
profiler.PrineDebug($"sometext_{five}_{six}");
}
}
Run Code Online (Sandbox Code Playgroud)
在 BenchmarkDotNet 下运行此基准测试..结果如下:
| Method | Mean | Error | …Run Code Online (Sandbox Code Playgroud)