AddBusinessDays and GetBusinessDays

I need to find 2 elegant complete implementations of public static DateTime AddBusinessDays(this DateTime date, int days) { // code here } and public static int GetBusinessDays(this DateTime start, DateTime end) { // code here } O(1) preferable (no loops). EDIT: By business days i mean working days (Monday, Tuesday, Wednesday, Thursday, Friday). No holidays, just weekends excluded. I

AddBusinessDays和GetBusinessDays

我需要找到2个完美的完整实现 public static DateTime AddBusinessDays(this DateTime date, int days) { // code here } and public static int GetBusinessDays(this DateTime start, DateTime end) { // code here } O(1)更好(没有循环)。 编辑:工作日我的意思是工作日(星期一,星期二,星期三,星期四,星期五)。 没有假期,只是周末排除在外。 我已经有一些看起来可行的丑陋解决方案,但我想知道是否有

Is it possible to tell the branch predictor how likely it is to follow the branch?

Just to make it clear, I'm not going for any sort of portability here, so any solutions that will tie me to a certain box is fine. Basically, I have an if statement that will 99% of the time evaluate to true, and am trying to eke out every last clock of performance, can I issue some sort of compiler command (using GCC 4.1.2 and the x86 ISA, if it matters) to tell the branch predictor that i

是否有可能告诉分支预测器跟随分支的可能性有多大?

为了清楚起见,我不打算在这里进行任何可移植性,所以任何将我与某个盒子绑定的解决方案都可以。 基本上,我有一个if语句,将99%的时间评估为真,并且试图排除性能的每个最后时钟,我可以发出某种编译器命令(使用GCC 4.1.2和x86 ISA,if它很重要)告诉分支预测器它应该缓存该分支? 是。 http://kerneltrap.org/node/4705 __builtin_expect是gcc(versions> = 2.96)为程序员提供分支预测信息给编译器的方法。 __bu

Are there any concurrency debugging tools for C#.NET in VS2010

On the project I am working on at the moment we have an unknown number of flickering tests which fail at varying rates (anywhere from every-other run to once every 5000 runs) which has led us to believe we have some serious Heisenbugs to resolve. Most of the time including trace statements in the code change the timing enough to eliminate these errors, or at least make them occur less often, but

VS2010中是否有针对C#.NET的并发调试工具?

在我目前正在进行的项目中,我们有不明数量的闪烁测试,这些测试以不同的速率失败(从每隔一次运行到每5000次运行一次),这导致我们认为我们有一些严重的Heisenbug要解决。 大多数情况下,包括代码中的跟踪语句都会改变时序以消除这些错误,或者至少使其发生次数减少,但显然这不是有效的错误修复。 我们想知道是否有与Visual Studio 2010一起使用的CHESS(http://research.microsoft.com/en-us/projects/chess/download.asp

Intersperse a List<>

Possible Duplicate: Extension method for Enumerable.Intersperse? I have a List<string> like this: "foo", "bar", "cat" I want it to look like this: "foo", "-", "bar", "-", "cat" Is there a C# method that does that? You can make an extension that returns an IEnumerable<T> with interspersed item

分散列表<>

可能重复: Enumerable.Intersperse的扩展方法? 我有一个像这样的List<string> : "foo", "bar", "cat" 我希望它看起来像这样: "foo", "-", "bar", "-", "cat" 有没有一种C#方法可以做到这一点? 您可以创建一个扩展,该扩展返回带有散布项的IEnumerable<T> : public static class ListExtensions { public

Class static?

I'm currently having a Class named "SqlData", which contains all the Methods needed to Connect to my MS-SQL Database. It contains methods for Inserting, Deleting and Updating different kinds of tables - and therefore is used in many Windows of my WPF application. Let's say that nearly 90% of my WPF-Windows are calling at least three Methods of my SqlData Methods for Loading,

类静态?

我目前有一个名为“SqlData”的类,其中包含连接到我的MS-SQL数据库所需的所有方法。 它包含插入,删除和更新不同类型表的方法 - 因此在我的WPF应用程序的许多Windows中使用。 假设接近90%的WPF-Windows正在调用至少三种我用于加载,插入和更新不同记录的SqlData方法的方法... 目前,我需要在每个窗口中实例化我的Sql-Class - 因此我正在考虑让整个Class都是静态的,所以我不需要每次都实例化它。 但是我也读过,在与外

How can I validate if a file is name valid in Windows?

Is there a Windows API function that I can pass a string value to that will return a value indicating whether a file name is valid or not? I need to verify that a file name is valid, and I'm looking for an easy way to do it without re-inventing the wheel. I'm working in straight C, but targeting the Win32 API. If there's no such function built-in, how would I go about writing my

如何在Windows中验证文件是否为名称有效?

有没有一个Windows API函数,我可以传递一个字符串值,将返回一个值,指示文件名是否有效? 我需要验证一个文件名是否有效,并且我正在寻找一种简单的方法来做到这一点,而无需重新发明轮子。 我正在直接使用C语言,但针对的是Win32 API。 如果没有内置的这种功能,我将如何去写自己的? Windows是否有一个通用算法或模式来确定文件名有效性? 问题并不那么简单,因为它取决于您认为的“有效文件名”。 与UNC路径一起使

WCF Certificate Chain, verify programmatically

I'm trying to use certificates programmatically, rather than using the store. I'm creating X509Certificate2 's with filename and password. This works fine when I have manually added the root certificate to the Certificate Store in Trusted People. However, I'd rather not have to do that on every deployment - I'd rather deal with it programmatically too. When I remove the

WCF证书链,以编程方式验证

我试图以编程方式使用证书,而不是使用商店。 我使用文件名和密码创建X509Certificate2 。 当我手动将根证书添加到“受信任的人”中的证书存储区时,此工作正常。 但是,我宁愿不必在每次部署时都这样做 - 我宁愿以编程方式处理它。 当我从证书存储中删除根证书时,我收到一个异常。 我读过的一切似乎都说我必须手动将根证书添加到证书存储区,否则信任链将无法工作。 问题:是否有编程方式来设置信任链,因此我不必手动

balancing in parallel processing application

I'm building a network-distributed parallel processing application that uses a combination of CPU and GPU resources across many machines. The app has to perform some very computationally expensive operations on a very large dataset over thousands of iterations: for step = 0 to requested_iterations for i = 0 to width for j = 0 to height for k = 0 to depth matrix[i,j,k] =

平行处理应用程序

我正在构建一个网络分布式并行处理应用程序,它在许多机器上使用CPU和GPU资源的组合。 应用程序必须在数千次迭代中对非常大的数据集执行一些计算量非常大的操作: for step = 0 to requested_iterations for i = 0 to width for j = 0 to height for k = 0 to depth matrix[i,j,k] = G*f(matrix[i,j,k]) 另外,矩阵操作必须同步执行:即,每次迭代都取决于紧接之前的帧结果。 这个专用网格中包含专用

Run an external program in C# (cross

I have already seen System.Diagnostics, but I can't seem to figure out how to do what I want. The user specifies what program they want run. On Windows systems this would be something like "C://path/to/someProgram.exe", but on a linux system something like "/usr/bin/wine start /path/to/someProgram.exe" would be passed instead. My program passes additional parameters t

在C#中运行一个外部程序(交叉

我已经看到System.Diagnostics,但我似乎无法弄清楚如何做我想要的。 用户指定他们想要运行的程序。 在Windows系统中,这将是类似“C://path/to/someProgram.exe”,但在Linux系统上像“在/ usr / bin中/酒开始/path/to/someProgram.exe”将代替传递。 我的程序将其他参数传递给指定的并运行它。 我能做什么,可以在Windows和Linux系统上运行?

Cross Platform C?

I am running Linux Ubuntu 10.04 and I have a Windows 7 machine and a MacBook running Mac OS X 10.6.4. How can I write a simple C program (as in NOT QT!) like: #include <stdio.h> int main(int argc, char **argv) { printf("Hello Linux and Mac and Windows!") return 0; } to run on all my machines without having to compile this program on Ubuntu, then Windows 7, then Mac OS X? Could

跨平台C?

我运行Linux Ubuntu 10.04,我有一台Windows 7机器和一台运行Mac OS X 10.6.4的MacBook。 我该如何编写一个简单的C程序(如在NOT QT中): #include <stdio.h> int main(int argc, char **argv) { printf("Hello Linux and Mac and Windows!") return 0; } 在我的所有机器上运行,而无需在Ubuntu上编译此程序,然后是Windows 7,然后是Mac OS X? 我可以在Ubuntu中创建它并交叉编译它以在多个不同的操作系统