我有以下作为一个例子:
public enum HttpRequestHeader
{
Accept,
AcceptCharset
}
public static class HTTP
{
public static Hashtable HttpRequestHeaderString
{
get
{
Hashtable returnHashtable = new Hashtable();
returnHashtable.Add(HttpRequestHeader.Accept,"Accept");
returnHashtable.Add(HttpRequestHeader.AcceptCharset,"Accept-Charset");
return returnHashtable;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我将访问:
string HttpRequestHeaderString
= HTTP.HttpRequestHeaderStrings[HttpRequestHeader.Accept]
Run Code Online (Sandbox Code Playgroud)
多次.由于这是一个static
HashTable
,有没有更好的方法来更有效地提供相同的功能?
我知道我可以使用不同类型的集合来实现这个特定的解决方案,但如果我想使用HashTable
- 我有什么选择?
非常感谢提前SO!
我认为这个问题实际上是关于我对垃圾收集和变量引用的理解.但是我会继续推出一些代码供你查看.
//请注意不要将此代码用于异步套接字,只是为了突出我的问题
// SocketTransport
// This is a simple wrapper class that is used as the 'state' object
// when performing Async Socket Reads/Writes
public class SocketTransport
{
public Socket Socket;
public byte[] Buffer;
public SocketTransport(Socket socket, byte[] buffer)
{
this.Socket = socket;
this.Buffer = buffer;
}
}
// Entry point - creates a SocketTransport, then passes it as the state
// object when Asyncly reading from the socket.
public void ReadOne(Socket socket)
{
SocketTransport socketTransport_One …
Run Code Online (Sandbox Code Playgroud) 我目前正在c#中构建一个DHCPMessage类.
RFC可在此处获取:http://www.faqs.org/rfcs/rfc2131.html
伪
public object DHCPMessage
{
bool[8] op;
bool[8] htype;
bool[8] hlen;
bool[8] hops;
bool[32] xid;
bool[16] secs;
bool[16] flags;
bool[32] ciaddr;
bool[32] yiaddr;
bool[32] siaddr;
bool[32] giaddr;
bool[128] chaddr;
bool[512] sname;
bool[1024] file;
bool[] options;
}
Run Code Online (Sandbox Code Playgroud)
如果我们想象每个字段都是固定长度的位数组,那么:
将此表示为一个类的方式???
或者..你会怎么写这个?:)
如何检查FileInfo对象是否是DirectoryInfo的后代?
public bool IsFileDescendantOfDirectory(
FileInfo fileInfo,
DirectoryInfo directoryInfo)
{
}
Run Code Online (Sandbox Code Playgroud) c# ×4
.net ×1
asynchronous ×1
construction ×1
fileinfo ×1
hashtable ×1
sockets ×1
static ×1
syntax ×1
variables ×1