我不希望VB.NET和C#开发者之间发生战争,我的目标也不是打开C#VS VB.NET对抗.
我希望大家列出一个在C#中大量使用的功能,但在VB.NET 2.0中不可用,你将如何解决类似的行为或目的呢?
例如:
C#
接受void(return)lambda表达式.这是FNH映射的示例:
Component(x => x.Address, m => {
m.Map(x => x.Number);
m.Map(x => x.Street);
m.Map(x => x.PostCode);
});
Run Code Online (Sandbox Code Playgroud)
这在VB.NET 4.0之前是不可能的(假设在VB.NET 4.0中可行)
VB.NET
必须编写一个帮助方法(Sub),并提供AddressOf这个方法以便解决.
Private Sub Helper(ByVal m As MType)
m.Map(Function(x) x.Number)
m.Map(Function(x) x.Street)
m.Map(Function(x) x.PostCode)
End Sub
...
Component(Function(x) x.Address, AddressOf Helper)
Run Code Online (Sandbox Code Playgroud)
现在我知道,它不是VB.NET 2.0,但这只是一个例子.VB.NET 3.0和3.5也可以使用.请提一下这个版本的VB.NET.
我得到以下异常:
Exception Type: System.InvalidOperationException
Exception Message: The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).
Exception Stack: at System.Threading.SynchronizationContextSwitcher.Undo()
at System.Threading.ExecutionContextSwitcher.Undo()
at System.Threading.ExecutionContext.runFinallyCode(Object userData, Boolean exceptionThrown)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteBackoutCodeHelper(Object backoutCode, Object userData, Boolean exceptionThrown)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.ContextAwareResult.Complete(IntPtr …
Run Code Online (Sandbox Code Playgroud) 在学习如何在计算机中表示浮点数时,我遇到了"偏差值"一词,我不太明白.
浮点数中的偏差值与浮点数的指数部分的负和正有关.
浮点数的偏差值为127,这意味着127总是被添加到浮点数的指数部分.这样做有助于确定指数是否为负数或正数?
我必须加载一些带有西里尔符号的 url。我的脚本应该适用于这个:
如果我将在浏览器中使用它,它将被替换为普通符号,但 urllib 代码失败并出现 404 错误。如何正确解码这个网址?
当我直接在代码中使用那个 url 时,比如 address = 'that address',它工作得很好。但是我使用解析页面来获取这个 url。我有一个包含西里尔字母的 url 列表。也许他们的编码不正确?这是更多代码:
requestData = urllib2.Request( %SOME_ADDRESS%, None, {"User-Agent": user_agent})
requestHandler = pageHandler.open(requestData)
pageData = requestHandler.read().decode('utf-8')
soupHandler = BeautifulSoup(pageData)
topicLinks = []
for postBlock in soupHandler.findAll('a', href=re.compile('%SOME_REGEXP%')):
topicLinks.append(postBlock['href'])
postAddress = choice(topicLinks)
postRequestData = urllib2.Request(postAddress, None, {"User-Agent": user_agent})
postHandler = pageHandler.open(postRequestData)
postData = postHandler.read()
File "/usr/lib/python2.6/urllib2.py", line 518, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 404: Not Found
Run Code Online (Sandbox Code Playgroud) 我的问题在代码中,但基本上我想知道如何/如果我可以做两个注释掉的行?我知道我可以在构造函数中完成它,但我不想!
struct foo
{
int b[4];
} boo;
//boo.b[] = {7, 6, 5, 4}; // <- why doesn't this work? (syntax error : ']')
//boo.b = {7, 6, 5, 4}; // <- or else this? (syntax error : '{')
boo.b[0] = 7; // <- doing it this way is annoying
boo.b[1] = 6; // :
boo.b[2] = 5; // :
boo.b[3] = 4; // <- doing it this way is annoying
boo.b[4] = 3; // <- why does this work! …
Run Code Online (Sandbox Code Playgroud) 我已经构建了一个小的asp.net表单,可以搜索某些内容并显示结果.我想在搜索结果中突出显示搜索字符串.例:
Query: "p"
Results: a<b>p</b>ple, banana, <b>p</b>lum
Run Code Online (Sandbox Code Playgroud)
我的代码是这样的:
public static string HighlightSubstring(string text, string substring)
{
var index = text.IndexOf(substring, StringComparison.CurrentCultureIgnoreCase);
if(index == -1) return HttpUtility.HtmlEncode(text);
string p0, p1, p2;
text.SplitAt(index, index + substring.Length, out p0, out p1, out p2);
return HttpUtility.HtmlEncode(p0) + "<b>" + HttpUtility.HtmlEncode(p1) + "</b>" + HttpUtility.HtmlEncode(p2);
}
Run Code Online (Sandbox Code Playgroud)
我主要是工作,但尝试用例如HighlightSubstring("ß", "ss")
.这崩溃是因为在德国,"ß"和"ss"被认为是相同的IndexOf
方法,但它们有不同的长度!
现在,如果有办法找出"文本"中的匹配有多长,那就没关系了.请记住,这个长度可以!= substring.Length
.
那么如何找出IndexOf
在存在连字和外来语言字符时出现的匹配长度(在这种情况下是连字)?
我确信这是一个非常基本的问题,但无论如何都要进行!我已经读过XSLT中文本和属性节点的内置模板规则
<xsl:template match="text()|@*">
<xsl:value-of select="."/>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
但是对于源文档
<?xml version="1.0"?>
<booker>
<award>
<author blah="test">Aravind Adiga</author>
<title>The White Tiger</title>
<year>2008</year>
</award>
</booker>
Run Code Online (Sandbox Code Playgroud)
和XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)
我得到以下输出应用Visual Studio中的转换.有人可以解释为什么我在输出中没有看到"测试"吗?
Aravind Adiga
白虎
2008年
这是昨天批判我的堆调试器的后续行动.正如bitc所建议的,我现在将分配的块的元数据保存在单独的手写哈希表中.
堆调试器现在检测到以下类型的错误:
欢迎提前讨论和感谢!
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <new>
namespace
{
// I don't want to #include <algorithm> for a single function template :)
template <typename T>
void my_swap(T& x, T& y)
{
T z(x);
x = y;
y = z;
}
typedef unsigned char byte;
const byte CANARY[] = {0x5A, 0xFE, 0x6A, 0x8D,
0x5A, 0xFE, 0x6A, 0x8D,
0x5A, 0xFE, 0x6A, 0x8D,
0x5A, 0xFE, 0x6A, 0x8D};
bool canary_dead(const byte* cage)
{ …
Run Code Online (Sandbox Code Playgroud) 这段代码有什么问题?
for (int w = 0; w < this.Controls.Count; w++)
{
if (this.Controls[w] is TransparentLabel)
{
la = (TransparentLabel)this.Controls[w];
if (la.Name != "label1")
{
la.Visible = false;
la.Click -= new System.EventHandler(Clicked);
this.Controls.Remove(this.Controls[w]);
la.Dispose();
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想从标签中清除屏幕,但它不起作用.