小编oli*_*dev的帖子

开源 C# 套接字 (TCP + UDP) 库

我对 .NET 框架的标准套接字类感到头疼。

有人可以推荐一个高效的开源 C# 套接字 (TCP + UDP) 库来处理套接字消息吗?

c# sockets

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

2D阵列的两个方向之间的性能测试

此代码(A)的执行速度比第二个快得多(10倍):

for(int w=0; w<width; w++) {
        for(int h=1; h<height; h++) {
            image[h][w] = (1-a)*image[h][w] + a*image[h-1][w];
        }
    }
Run Code Online (Sandbox Code Playgroud)

第二个:

for(int h=0; h<height; h++) {
        for(int w=1; w<width; w++) {
            image[h][w] = (1-a)*image[h][w] + a*image[h][w-1];
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是为什么?在水平或垂直方向上遍历图像中的所有像素是相同的.

有没有办法加快第二个?

提前致谢.

c++ image-processing

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

使用7zip sdk压缩文件,但无法使用winrar或7zip解压缩

我从这里下载了SDK 7zip .

然后我使用此代码将文件压缩为7zip:

private static void CompressFileLZMA(string inFile, string outFile)
{
    Encoder coder = new SevenZip.Compression.LZMA.Encoder();

    using (FileStream input = new FileStream(inFile, FileMode.Open))
    using (FileStream output = new FileStream(outFile, FileMode.Create))
    {
        coder.Code(input, output, -1, -1, null);
        output.Flush();
    }
}
Run Code Online (Sandbox Code Playgroud)

我在网站上尝试了SDK版本9.20和9.22 beta.

压缩似乎正在压缩我的文件:1.6 MB到239 KB.

但是,如果我使用WinRar或7zip进行解压缩.他们无法识别存档文件,错误就像

"未知存档文件或损坏的文件"

对此有何看法?

.net c# compression 7zip

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

如何更改我的C++代码以在C#中用作DLL?

我正在学习如何用C#调用C++中的方法.我做了一些研究,看起来Pinvoke是一个很好的方式.

如何将这个简单的C++代码转换为在C#中调用它的方式,以及如何编写要在C#中调用的方法?

我有一个头文件:

MathFuncsLib.h

namespace MathFuncs
{
    class MyMathFuncs
    {
         public:            
       double Add(double a, double b);
       MyMathFuncs getClass();
    };
}
Run Code Online (Sandbox Code Playgroud)

MathFuncsLib.cpp

#include "MathFuncsLib.h"
namespace MathFuncs
{
   MyMathFuncs MyMathFuncs::getClass() {
       return *(new MyMathFuncs());
   }

   double MyMathFuncs::Add(double a, double b) {
       return a + b;
   }
}
Run Code Online (Sandbox Code Playgroud)

在C#中,

我想拥有:

main()
{
    MyMathFuncs abd = MyMathFuncs::getClass();
    abd.Add(1.2, 2.3);
}
Run Code Online (Sandbox Code Playgroud)

我不知道应该如何实现,所以我认为最好问一下.

c# c++ pinvoke

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

如何转换LPWSTR到'const char*'

使用C++/CLI从C#到C++获取结构后:

public value struct SampleObject
{   
    LPWSTR a;    
};
Run Code Online (Sandbox Code Playgroud)

我想打印它的实例:

printf(sampleObject->a);
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误:

错误1错误C2664:'printf':无法将参数1从'LPWSTR'转换为'const char*'

我怎样才能转换LPWSTR to char*

提前致谢.

c++ c++-cli

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

Jquery:在父div中的索引处选择一个子div

如果我有:

<div id='parent'> 
  <table> 
        <tr> 
            <td> 
                <div id='child1'></div> 
            </td> 
        </tr> 
        <tr> 
             <td> 
                <div id='child2'></div> 
             </td> 
        </tr> 
    </table>
 </div> 
Run Code Online (Sandbox Code Playgroud)

我试过:$('#parent> table> tr:eq(1)> div');

我想在其索引中选择一个特定的子div.例如,我想选择第二个子div child2.一个简单的解决方案是:

var div2 = $('#child2');
Run Code Online (Sandbox Code Playgroud)

但我更愿意与 div 一起这样做:

var div2 = $('#parent div')...get(1); // 1 is the index.
Run Code Online (Sandbox Code Playgroud)

这可能吗?

jquery

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

公式表达式结果

在Java中,如果我有一个字符串:

String abc = "(5)*(2+2)/(2)";
Run Code Online (Sandbox Code Playgroud)

我怎么能得到结果abc = 10

java

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

Java replaceAll函数的字符串不替换

可能重复:
使用replaceall输出错误

如果我有字符串:

String test = "replace()thisquotes";

test = test.replaceAll("()", "");
Run Code Online (Sandbox Code Playgroud)

测试结果仍然是: test = "replace()thisquotes"

所以()没有被替换.

有任何想法吗?

java

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

如何保护类直接实例化

我该如何更改此实现:

public interface Animal()
{
   public void eat();
}

public class Dog implements Animal
{
   public void eat()
   {}
}

public void main()
{
   // Animal can be instantiated like this:
  Animal dog = new Dog();

  // But I dont want the user to create an instance like this, how can I prevent this declaration?
  Dog anotherDog = new Dog();
}
Run Code Online (Sandbox Code Playgroud)

java uml

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

我如何动态切换不同的语言资源文件?

在我的wpf项目中,我添加了两个资源文件:

Resources\English.resx and Resources\German.resx
Run Code Online (Sandbox Code Playgroud)

在MainWindow.xml中,我尝试从资源文件中查找值:

<Window x:Uid="Window_1" x:Class="LocalizationInvestigate.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Resources="clr-namespace:LocalizationInvestigate.Resources"
        Title="MainWindow" Height="350" Width="525">
    <Grid x:Uid="Grid_1">
        <Label x:Uid="Label_1" Content="{x:Static Resources:English.LabelHello}"></Label>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

对于英语,它以这种方式完美地运作.但是,基于本地语言,我如何使用以下内容自动切换到德语:资源:German.LabelHello?

wpf localization

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

标签 统计

c# ×3

c++ ×3

java ×3

.net ×1

7zip ×1

c++-cli ×1

compression ×1

image-processing ×1

jquery ×1

localization ×1

pinvoke ×1

sockets ×1

uml ×1

wpf ×1