小编Cha*_*ion的帖子

这个API可以改进吗?

在我们的CORE库中,我们将此类作为20,000行抽象提供.你能看出它的设计方式有什么问题吗?

注1:此类具有SharpZipLib支持.

注2:SharpZipLib约为20K线.

public static class Compression
{
    public static Byte[] CompressBytes(Byte[] input);
    public static Byte[] CompressBytes(Byte[] input, Format format);
    public static Byte[] CompressBytes(Byte[] input, Format format, Level level);

    public static Byte[] DecompressBytes(Byte[] input);
    public static Byte[] DecompressBytes(Byte[] input, Format format);

    public static String CompressString(String input);
    public static String CompressString(String input, Format format);
    public static String CompressString(String input, Format format, Level level);

    public static String DecompressString(String input);
    public static String DecompressString(String input, Format format);

    public static void CompressFile(String input_file_path, String …
Run Code Online (Sandbox Code Playgroud)

c# api refactoring

3
推荐指数
2
解决办法
475
查看次数

为什么托管语言不能提供手动删除对象的功能?

假设您想编写一个处理大型数据集的高性能方法.为什么开发人员不能开启手动内存管理而不是被迫转向C或C++?

void Process()
{
    unmanaged
    {
        Byte[] buffer;
        while (true)
        {
            buffer = new Byte[1024000000];

            // process

            delete buffer;
        } 
    }   
}
Run Code Online (Sandbox Code Playgroud)

language-agnostic garbage-collection memory-management managed-code

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

一个类是否应该有静态和非静态成员

我想弄清楚什么时候适合一个类同时具有静态和非静态函数.又名:

$obj = new ClassA;
$obj->doOOPStuff();

$something = ClassA::doStaticStuff();
Run Code Online (Sandbox Code Playgroud)

注意:此示例在PHP中完成,但问题是语言无关.

似乎如果你有一个要实例化的类,任何可以静态调用的函数,很可能属于另一个类.

有没有可行的案例,我会有一个使用静态和非静态成员的类?

language-agnostic oop

3
推荐指数
2
解决办法
292
查看次数

MailboxProcessor类型是锁的替代品吗?

我一直在慢慢研究F#带来的所有功能.一个特别引起我兴趣的是MailboxProcessor.

  1. 在C#中相当于这个很可能使用锁.我们可以将其MailboxProcessor视为锁的替代品吗?
  2. 在下面的例子中,我做了什么特别天真的事情,或者你能看到任何可以改进的东西吗?


module Tcp =
    open System
    open System.Collections.Generic
    open System.Net
    open System.Net.Sockets
    open System.Threading    

    type SocketAsyncMessage =
        | Get of AsyncReplyChannel<SocketAsyncEventArgs>
        | Put of SocketAsyncEventArgs
        | Dispose of AsyncReplyChannel<MailboxProcessor<SocketAsyncMessage>>

    type SocketAsyncEventArgsPool(size:int) =             
        let agent = 
            lazy(MailboxProcessor.Start(
                    (fun inbox ->
                        let references = lazy(new List<SocketAsyncEventArgs>(size))       
                        let idleReferences = lazy(new Queue<SocketAsyncEventArgs>(size))                    
                        let rec loop () = 
                            async {
                                let! message = inbox.Receive()
                                match message with
                                | Get channel -> 
                                    if idleReferences.Value.Count > 0 then
                                        channel.Reply(idleReferences.Value.Dequeue())
                                    else …
Run Code Online (Sandbox Code Playgroud)

concurrency f# message-passing

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

C#属性引用类型?

我从C#开始,我有一个问题.

说我有一个对象:

Person
Run Code Online (Sandbox Code Playgroud)

以及名为Cat的人物:

Person.Cat
Run Code Online (Sandbox Code Playgroud)

如果我做:

Cat cat = new Cat(stuff);
cat.Name = "Alan";
Person.Cat = cat;
Run Code Online (Sandbox Code Playgroud)

猫是猫直接参考吗?如果我做:

Person.Cat.Name = "John";
Run Code Online (Sandbox Code Playgroud)

猫的名字会是"约翰"吗?

因为我觉得我之前尝试过这样的事情,并且我得到了NullReferenceException或类似的东西.

c#

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

为什么我的代码不能编译?

let sub (m:double[],n:double[]) : double[]=
    [| for i = 0 to Array.length m -1 do m.[i]-n.[i] |]
Run Code Online (Sandbox Code Playgroud)

错误1此值不是函数且无法应用E:\ MyDocuments\Visual Studio 2010\Projects\curve intersection \newton\Module1.fs 27 21 newton

但是,这没关系:

let a = [| "a"; "b"; "c"; "d"; "e"; "f" |]

for i = 0 to Array.length a - 1 do
    System.Console.WriteLine(a.[i])
Run Code Online (Sandbox Code Playgroud)

f#

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

我需要一个单选按钮的事件触发器,当它被取消选中时,因为检查了另一个按钮

我需要一个单选按钮的事件触发器,当它被取消选中时,因为检查了另一个按钮.

下面的代码应该证明我的困境.

如果你注意到,有一个onchange事件触发器附加到每个单选按钮和html代码中的复选框.从理论上讲,状态从检查到未检查的变化应该触发onchange事件.

这与复选框的预期一致.如果您选中一个,则会收到警告"您的项目已更改为已选中".如果取消选中它,则会收到警告"您的项目已更改为未选中".

使用单选按钮,当您选中按钮1时,您会按预期获得警报"您的项目已更改为已选中",因为该按钮已从未选中更改为已选中.但是,当您选中第二个按钮并且第一个单选按钮从已选中更改为未选中时,"onchange"事件触发器不会触发,并且不会触发"其他"警报.

所以对我来说这个问题是当一个单选按钮被另一个被检查的按钮取消选中时会触发什么事件?

我感谢大家对此的帮助.

--Kenoli

    <html>
<head>
<title></title>

<script type="text/javascript">

function clickAction() {

    //alert ('Your item changed');

    if (this.checked == true) {alert ('Your item is changed to checked');}

    else if (this.checked == false) {alert('Your item is changed to unchecked');}

}



</script>

<script type="text/javascript">

function initializeToggles() {

    var button1= document.getElementById('button1');
    button1.onchange = clickAction;

    var box1= document.getElementById('box1');
    box1.onchange = clickAction;

    var box2= document.getElementById('box2');
    box2.onchange = clickAction;

}

</script>

<script type="text/javascript">window.onload = initializeToggles;</script>

</head>
<body>

<input type="radio" name="testRadio" id="button1" >Button …
Run Code Online (Sandbox Code Playgroud)

javascript

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

定义这个通用接口以便编译的最简洁方法是什么?

因为,具有相同参数但返回值不同的两个方法将无法编译.在不失去清晰度的情况下定义此界面的最佳方法是什么?

public interface IDuplexChannel<T, U>
{
    void Send(T value, int timeout = -1);
    void Send(U value, int timeout = -1);
    bool TrySend(T value, int timeout = -1);
    bool TrySend(U value, int timeout = -1);
    T Receive(int timeout = -1);
    U Receive(int timeout = -1);
    bool TryReceive(out T value, int timeout = -1);
    bool TryReceive(out U value, int timeout = -1);
}
Run Code Online (Sandbox Code Playgroud)

我考虑使用params,但这会使它使用起来有点尴尬.

public interface IDuplexChannel<T, U>
{
    void Send(T value, int timeout = -1);
    void Send(U value, int timeout = …
Run Code Online (Sandbox Code Playgroud)

.net c# generics c#-4.0

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

SQL查询 - 从两个不同级别的层次结构中获取总和

项目有多个任务,具有多个任务

项目(1-n) - >任务(1-n) - >作业

"任务"表上的字段是"计划时数".

"分配"表上的字段为"分配小时".

如何在单个查询中获取所有项目的计划时间和分配时间?

sql t-sql sql-server

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

VB.NET - 想要将两种可空类型相加 - 如何?(即var1 + var2,两者都可以为空,vari1 = Nothing,Var2 = 5导致Nothing)

我有:

Dim nVar1 As Long?

Dim nVar2 As Long?

Dim nVarSum As Long?

nVar1 = Nothing

nVar2 = 5

nVarSum = nVar1 + nVar2
Run Code Online (Sandbox Code Playgroud)

我希望结果以nVarSum为5结束,而不是Nothing.

我知道如果你添加一些未知值的东西,你最终会得到"somthing + unknown"或者x + 5总是等于"x + 5"而不是"5",因为你仍然带着那个未知的"x".

但是,在这种情况下,如何才能有效地将未知或Nothing视为零?

谢谢!

(基本上发生的是最终用户向我们发送数据文件,此代码解析该文件,然后将大约15个字段汇总在一起.如果用户将这些字段留空而不是为它们分配零,我需要对待它好像它对于这一个加法操作是零,但所有其余代码需要继续将其视为Nothing值,因为用户实际上没有提交零...他们提交空白或没有)

vb.net nullable addition

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