在我们的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或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
我想弄清楚什么时候适合一个类同时具有静态和非静态函数.又名:
$obj = new ClassA;
$obj->doOOPStuff();
$something = ClassA::doStaticStuff();
Run Code Online (Sandbox Code Playgroud)
注意:此示例在PHP中完成,但问题是语言无关.
似乎如果你有一个要实例化的类,任何可以静态调用的函数,很可能属于另一个类.
有没有可行的案例,我会有一个使用静态和非静态成员的类?
我一直在慢慢研究F#带来的所有功能.一个特别引起我兴趣的是MailboxProcessor.
MailboxProcessor视为锁的替代品吗?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) 我从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或类似的东西.
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) 我需要一个单选按钮的事件触发器,当它被取消选中时,因为检查了另一个按钮.
下面的代码应该证明我的困境.
如果你注意到,有一个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) 因为,具有相同参数但返回值不同的两个方法将无法编译.在不失去清晰度的情况下定义此界面的最佳方法是什么?
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) 项目有多个任务,具有多个任务
项目(1-n) - >任务(1-n) - >作业
"任务"表上的字段是"计划时数".
"分配"表上的字段为"分配小时".
如何在单个查询中获取所有项目的计划时间和分配时间?
我有:
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值,因为用户实际上没有提交零...他们提交空白或没有)
c# ×3
f# ×2
.net ×1
addition ×1
api ×1
c#-4.0 ×1
concurrency ×1
generics ×1
javascript ×1
managed-code ×1
nullable ×1
oop ×1
refactoring ×1
sql ×1
sql-server ×1
t-sql ×1
vb.net ×1